简体   繁体   中英

Send email using live server SMTP server through PHP Mailer not working

I am using PHPMailer v6 and trying to send mail from a shared server email. my codes :

require_once "vendor/autoload.php";
$mail = new PHPMailer;
$mail->SMTPDebug = 3;                               
$mail->isSMTP();                                     
$mail->Host = 'cp-ht-1.webhostbox.net';
$mail->SMTPAuth = true;                               
$mail->Username = 'info@gitanjaliadvertising.com'; 
$mail->Password = "**********";                           
$mail->SMTPSecure = "ssl";                           
$mail->Port = 465;                                   
$mail->From = "abc@gmail.com";
$mail->FromName = "Full Name";
$mail->addAddress("xyz@gmail.com", "Recepient Name");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send()) 
{
echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
echo "Message has been sent successfully";
}

if i run the page it shows success message but no any mail in my inbox. on debug I got :

CLIENT: 250 Message denied for spoofing attempt via SMTP Auth

If I used my gmail details then its working fine but don't know what is the problem with the server mail details .I have searched so many articles but did not get any solution. Some people said to remove the following line but its not working..

$mail->isSMTP();

please help

As the error says it clearly you're trying to do email spoofing.

CLIENT: 250 Message denied for spoofing attempt via SMTP Auth

More information on email spoofing:

Email spoofing is the forgery of an email header so that the message appears to have originated from someone or somewhere other than the actual source. Email spoofing is a tactic used in phishing and spam campaigns because people are more likely to open an email when they think it has been sent by a legitimate source.

Solution: As I can see in your code you have set up $mail->From to a gmail account. which is not owned by your domain and will end up failing.

Change $mail->SetFrom = "abc@gmail.com"; to $mail->SetFrom = "info@gitanjaliadvertising.com";

You can add replyTo to "abc@gmail.com" if you want replied to go to "abc@gmail.com"

Thanks.

You can use below code and library. i think this will solve your problem.

include(class.phpmailer.php);
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'xxxxxx@gmail.com';
$mail->Password = ' mailpassword';

$mail->SetFrom('xxxxx@gmail.com');
$mail->Subject = 'Account Activation';
$mail->Body = 'testing';
$mail->Body .= 'Click here to Activate';
$mail->AddAddress("xxxx@gmail.com');
if(!$mail->Send()){
echo 'Mailer error: ' . $mail->ErrorInfo;
}else{
echo 'Message has been sent.';
}
?>

and you can get library file in this url

https://github.com/mktomanikandan/phpmailer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM