0
votes

require_once('class.phpmailer.php');
$mail = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure="tls";
$mail->Host = "smtp.mail.yahoo.com";
$mail->Port = 587;
$mail->Username = "********@yahoo.com";
$mail->Password = "*****";

$mail->SetFrom('*********@yahoo.com', 'my name');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML('text');
$mail->AddAddress('*********@yahoo.com', 'my name');

if($mail->Send()) {
    echo "Message sent!";
}else {
    echo "Mailer Error: " . $mail->ErrorInfo;
}

So, I try to send an Email with PHPMailer, but the code it does not work,the localhost page isn't working. I copied class.phpmailer.php and class.smtp.php to /var/www/html folder (Before I specified the path in require_once (/usr/share/...)). I enabled ssl extension. I use Ubuntu 16.04 and I installed libphp-phpmailer. What should I do? (Any options to send mail with smtp would be apreciated, already tried: postfix and sendmail).

2
"doesn't work", "isn't working" are no use for telling what's going on. It looks like you're using a very old version of PHPMailer, so get the latest.Synchro

2 Answers

0
votes

go through the above comment link..!!

try this

<?php
include "PHPMailer_5.2.4/class.phpmailer.php"; 
$mail = new PHPMailer(); 

$mail->IsSMTP(); 
$mail->SMTPDebug = 1; 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com";

$mail->Port = 465; 
$mail->IsHTML(true);
$mail->Username = "******@gmail.com";
$mail->Password = "*******";

$mail->SetFrom('aswad@yahoo.com', 'my name');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML('text');
$mail->AddAddress('aswad@yahoo.com', 'my name');

if($mail->Send()) {
    echo "Message sent!";
}else {
    echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
0
votes

try to comment the

$mail->IsSMTP();

line

also check the SELinux config

on the shell type

sestatus -b | grep sendmail

if you see that httpd_can_sendmail off

just type this 2 lines:

  1. restorecon /usr/sbin/sendmail
  2. setsebool -P httpd_can_sendmail 1