Posted on : 2020-05-20 15:02:16 View Type: public
Jeremy Blur
Hi
How can I setup SMTP to send email
Thank you
Hi
How can I setup SMTP to send email
Thank you
There is a file in lib >> includes >> functions.php in which you can find a function send_mail() that function is used to send all mails of system. You can apply SMTP using PHPmailer in that function. Currently script doesn't allow this through its system you have to do this manually. Thanks.
function send_email($mailto, $subject, $message) {
//getting set email addresses from database.
$from_email = get_option('email_from');
$reply_to = get_option('email_to');
$mailheaders = "From:".$from_email;
$mailheaders .="Reply-To:".$reply_to;
$from = $from_email;
$filename = '';
$fileatt_type = '';
$headers = "FROM: ".$from;
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$filename}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
mail($mailto, $subject, $message, $headers);
}
In this function you can catch all the varialbles and process them using PHPmailer or your fav SMTP script.
Hi,
Ok, I have checked this file, but I don't see the PHPmailer script.
So I have to install phpmailer, correct ?
I'm asking just to avoid using 2 times the same library in the script
Create a new directory mailer and place these phpmailer files in
includes >> mailer
Now edit your system_load.php from root folder and include PHPMailer class.
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'lib/includes/mailer/Exception.php';
require 'lib/includes/mailer/PHPMailer.php';
$mail = new PHPMailer;
You can include this before these lines
include('lib/includes/localize.php');
include('lib/includes/functions.php');
include('lib/includes/update.php');
Now change your send_mail function with
function send_email($mailto, $subject, $message) {
global $mail;
//getting set email addresses from database.
$from_email = get_option('email_from');
$reply_to = get_option('email_to');
$mail->setFrom($from_email, 'Your business name');
$mail->addAddress($mailto, '');
$mail->Subject = $subject;
$mail->isHTML(true);
$mail->Body = $message;
$mail->send();
}
Further things about PHPMailer you may find on their documentation as per your requirements.
thanks. I would not able to help you anything further on this.
Click one of our contacts below to chat on WhatsApp
Do you have any questions?
