panduan php mailer


Status
Not open for further replies.

Rockman

Hosting Guru
Verified Provider
cara lain menurut provider hosting bisa menggunakan PHPmailer, kendalanya saya sama sekali tidak mengerti menggunakan PHPmailer.
untuk itu mohon bantuan nya .
Saya lebih setuju pendapat @FluidaWeb ,
Jika bisa pakai smtp mailer, disarankan pakai smtp mailer saja. Sebab banyak provider hosting yang kami jumpai disable phpmail, karena sering menyebabkan spam dan lainnya. Oleh karenanya lebih baik pelajari smtp mail saja.. .
 

antochoy

Expert 1.0
Verified Provider
Saya lebih setuju pendapat @FluidaWeb ,
Jika bisa pakai smtp mailer, disarankan pakai smtp mailer saja. Sebab banyak provider hosting yang kami jumpai disable phpmail, karena sering menyebabkan spam dan lainnya. Oleh karenanya lebih baik pelajari smtp mail saja.. .
saya juga setuju Pake SMTP...
tapi TS nanya , step by step untuk menggunakan PHPmailer.
PHPmailer itu classPHP utk ngirim email...
PHPmailer nanti menggunakan SMTP juga...
cuman dia blm tau implementasi penggunaan SMTP di dalam class PHPmailer
 

PremiumFastNet

Apprentice 2.0
Verified Provider
Install php mailer pakai composer pak, tinggal autoload..

Nanti set smtp akunnya saja.
 

antochoy

Expert 1.0
Verified Provider
Install php mailer pakai composer pak, tinggal autoload..

Nanti set smtp akunnya saja.
bisa kasih contoh skripnya om?
TS bilang uda download PHPmailernya... mungkin dia pake composer/git clone/ zip download
cuman dia blm tau implementasi penggunaan SMTP di dalam class PHPmailer
 
Last edited:

mkcipta

Beginner 2.0
saya bingung pak pada bagian //content

//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();

parameter bagian //Content bisa ambil dari $_POST formemail.html <<< ini saya tidak menemukan dalam formemail.html>>

berikut scrip formemail.html saya

<form action="sendemail.php" method="post" name="contactform">
<table width="450px">
<tbody>
<tr>
<td valign="top"><label for="first_name">First Name *</label></td>
<td valign="top"><input maxlength="50" name="first_name" size="30" type="text" /></td>
</tr>
<tr>
<td valign="top"><label for="last_name">Last Name *</label></td>
<td valign="top"><input maxlength="50" name="last_name" size="30" type="text" /></td>
</tr>
<tr>
<td valign="top"><label for="email">Email Address *</label></td>
<td valign="top"><input maxlength="80" name="email" size="30" type="text" /></td>
</tr>
<tr>
<td valign="top"><label for="telephone">Telephone Number</label></td>
<td valign="top"><input maxlength="30" name="telephone" size="30" type="text" /></td>
</tr>
<tr>
<td valign="top"><label for="comments">Comments *</label></td>
<td valign="top"><textarea cols="25" maxlength="1000" name="comments" rows="6"></textarea></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>





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


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
saya coba edit ulang formemail.html dan sendemail.php

===== form.html =====

<form method="post" action="sendemail.php">
Email: <input name="email" id="email" type="text" /><br />

Message:<br />
<textarea name="message" id="message" rows="15" cols="40"></textarea><br />

<input type="submit" value="Submit" />
</form>

==============================

==========sendemail.php=============
<?php


$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

// here we use the php mail function
// to send an email to:
// [email protected]
mail( "[email protected]", "Feedback Form Results",$message, "From: $email" );
?>
// 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 = 'mail.ayaxx.co.id'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = '***********'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('[email protected]', 'Web visitor');
$mail->addAddress('[email protected]', 'Info'); // Add a recipient
$mail->addAddress(''); // 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;
}

======================end======================


begitu saya mencoba melalui contact form nya error dengan messages

"Warning: mail() has been disabled for security reasons in /home/gugvfylt/public_html/sendemail.php on line 10
// 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 = 'mail.ayaxx.co.id'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = 'Pundarika1996'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to //Recipients $mail->setFrom('[email protected]', 'Web visitor'); $mail->addAddress('[email protected]', 'Info'); // Add a recipient $mail->addAddress(''); // 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 in bold!'; $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; }
 

kumbangasmara

Beginner 2.0
Sebelumnya salam kenal untuk para master & suhu2.
Boleh di coba
PHP:
<?php
/**
 * This example shows making an SMTP connection with authentication.
 */

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Asia/Jakarta');

require 'PHPMailerAutoload.php';
if(isset($_POST['submit']))
{
   
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$comments = $_POST['comments'];
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.domain.net";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "[email protected]";
//Password to use for SMTP authentication
$mail->Password = "domain";
//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo($email);
//Set who the message is to be sent to
$mail->addAddress('[email protected]', 'John Doe');
//Set the subject line
$mail->Subject = 'Contact Form';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
// Set email format to HTML
$mail->isHTML(true);

// Email body content
$mailContent = "<h1>$first_name $last_name $email $telephone Send HTML Email using SMTP in PHP</h1>
    <p>$comments.</p>";
$mail->Body = $mailContent;


//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
}

HTML:
<form action="smtp.php" method="post" name="contactform">
<table width="450px">
<tbody>
<tr>
<td valign="top"><label for="first_name">First Name *</label></td>
<td valign="top"><input maxlength="50" name="first_name" size="30" type="text" /></td>
</tr>
<tr>
<td valign="top"><label for="last_name">Last Name *</label></td>
<td valign="top"><input maxlength="50" name="last_name" size="30" type="text" /></td>
</tr>
<tr>
<td valign="top"><label for="email">Email Address *</label></td>
<td valign="top"><input maxlength="80" name="email" size="30" type="text" /></td>
</tr>
<tr>
<td valign="top"><label for="telephone">Telephone Number</label></td>
<td valign="top"><input maxlength="30" name="telephone" size="30" type="text" /></td>
</tr>
<tr>
<td valign="top"><label for="comments">Comments *</label></td>
<td valign="top"><textarea cols="25" maxlength="1000" name="comments" rows="6"></textarea></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>
Saya menggunakan Phpmailler versi 5.2.25 dan bisa disesuaikan sesuai kebutuhan
 

antochoy

Expert 1.0
Verified Provider
saya coba edit ulang formemail.html dan sendemail.php

===== form.html =====

<form method="post" action="sendemail.php">
Email: <input name="email" id="email" type="text" /><br />

Message:<br />
<textarea name="message" id="message" rows="15" cols="40"></textarea><br />

<input type="submit" value="Submit" />
</form>

==============================

==========sendemail.php=============
<?php


$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

// here we use the php mail function
// to send an email to:
// [email protected]
mail( "[email protected]", "Feedback Form Results",$message, "From: $email" );
?>
// 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 = 'mail.ayaxx.co.id'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = '***********'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('[email protected]', 'Web visitor');
$mail->addAddress('[email protected]', 'Info'); // Add a recipient
$mail->addAddress(''); // 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;
}

======================end======================


begitu saya mencoba melalui contact form nya error dengan messages

"Warning: mail() has been disabled for security reasons in /home/gugvfylt/public_html/sendemail.php on line 10
// 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 = 'mail.ayaxx.co.id'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = 'Pundarika1996'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to //Recipients $mail->setFrom('[email protected]', 'Web visitor'); $mail->addAddress('[email protected]', 'Info'); // Add a recipient $mail->addAddress(''); // 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 in bold!'; $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; }

kok pake skrip mail lagi: mail( "[email protected]", "Feedback Form Results",$message, "From: $email" );
 
Status
Not open for further replies.

Top