panduan php mailer


Status
Not open for further replies.

mkcipta

Beginner 2.0
Dear rekan2 DWH,

mohon bantuan dan saran nya, saat ini saya sedang membuat sebuah web sederhana utk perusahaan saya bekerja, namun saya mengalami kesulitan untuk membuat form email pada tab contact us.
pihak hosting sudah tidak mengijinkan function mail pada php, dan menyarankan saya menggunakan PHPmailer.

yang jadi pertanyaan, adakah tutorial step by step untuk menggunakan PHPmailer.?
atau Rekan2 disini ada yang mau berbagi info dan tips agar saya bisa mengaplikasina PHPmailer di website yg sedang saya buat.

saya sudah download PHP mailer dan hosting ke web, namun bingung darimana harus memulai, dan sudah cari di google tidak ada yg menjelaskan secara rinci.

PS : saya nubie sama sekali dan hanya bermodal google dalam pembuatan website ini.


salam.

m kurnia cipta
 

FluidaWeb

Hosting Guru
Sama seperti yang saya lakukan, phpmail didisable dan lebih disarankan pakai smtp mail, namun jika tidak ada cara lain bisa enable phpmail untuk user tertentu
 

mkcipta

Beginner 2.0
Sama seperti yang saya lakukan, phpmail didisable dan lebih disarankan pakai smtp mail, namun jika tidak ada cara lain bisa enable phpmail untuk user tertentu
cara lain menurut provider hosting bisa menggunakan PHPmailer, kendalanya saya sama sekali tidak mengerti menggunakan PHPmailer.
untuk itu mohon bantuan nya .
 

antochoy

Expert 1.0
Verified Provider
download/ git clone dulu class PHPMailer nya
https://github.com/PHPMailer/PHPMailer

cntohnya juga sudah ada pak,
tinggal masukkan parameter nya

PHP:
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
    $mail->addAddress('[email protected]');               // Name is optional
    $mail->addReplyTo('[email protected]', 'Information');
    $mail->addCC('[email protected]');
    $mail->addBCC('[email protected]');
    //Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
 

mkcipta

Beginner 2.0
gelar disini aja skrip form email dan php nya sekalian.. biar gampang bantunya

terlampir adalah form email nya, dan saya lampirkan juga script sendemail.php.

mohon masukan dari Tuan @antochoy
 

Attachments

  • sendemail.php.txt
    1.1 KB · Views: 5
  • formemail.html.txt
    1.1 KB · Views: 3

mkcipta

Beginner 2.0
download/ git clone dulu class PHPMailer nya
https://github.com/PHPMailer/PHPMailer

cntohnya juga sudah ada pak,
tinggal masukkan parameter nya

PHP:
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
    $mail->addAddress('[email protected]');               // Name is optional
    $mail->addReplyTo('[email protected]', 'Information');
    $mail->addCC('[email protected]');
    $mail->addBCC('[email protected]');
    //Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

sudah saya download dan sudah saya upload ke public_html , yang saya bingung langkah selanjut nya setelah input parameter bagaimana.?
apakah di bawah form email perlu di tambah kan
<script src="phpmailer/PHPmailer.php"></script>
agar script PHPmailer dipanggil pada saat klik tombol submit.?
 

antochoy

Expert 1.0
Verified Provider
download/ git clone dulu class PHPMailer nya
https://github.com/PHPMailer/PHPMailer

cntohnya juga sudah ada pak,
tinggal masukkan parameter nya

PHP:
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
    $mail->addAddress('[email protected]');               // Name is optional
    $mail->addReplyTo('[email protected]', 'Information');
    $mail->addCC('[email protected]');
    $mail->addBCC('[email protected]');
    //Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

silahkan eksekusi ini dulu pak
 

antochoy

Expert 1.0
Verified Provider
file php yang perlu di config itu file yg mana ya pak.?
saya cari di folder src, ngga ketemu ketemu..semua saya buka tp tidak ada yang format nya seperti lampiran Bapak ini..

skrip yg saya kasih tadi, masukkan ke sendemail.php, parameter bagian //Content bisa ambil dari $_POST formemail.html nya
 
Status
Not open for further replies.

Top