1 month before this code is working fine on website which hosting is provided by "godaddy" now hosting is renew by different server "namecheap" after renewing domain this error is occur during sending mail. I updated PHPMailer file but nothing happen.
An uncaught Exception was encountered Type: phpmailerException
Message: SMTP Error: The following recipients failed: abc@gmail.com: "Your IP: . . . : Your domain gmail.com is not allowed in header From"
Filename: /Directory_path/phpmailer/class.phpmailer.php
Line Number: 1585
Backtrace:
File: /Directory_path/phpmailer/class.phpmailer.php Line: 1337 Function: smtpSend
File: /home/Directory_path/phpmailer/class.phpmailer.php Line: 1215 Function: postSend
File: /Directory_path/views/contact.php Line: 34 Function: send
File: /Directory_path/controllers/Contact.php Line: 7 Function: view
$name= $_POST["name"];
$email = $_POST["email"];
$msg = $_POST["msg"];
require "phpmailer/PHPMailerAutoload.php";
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = "mail.domain_name.com";
$mail->port = 465;
$mail->SMTPAuth=true;
$mail->SMTPSecure = 'tls';
$mail->Username = "info@example.com";
$mail->Password = '********';
$file_name = $_FILES["attc"]["name"];
$tmp_name = $_FILES["attc"]["tmp_name"];
$path = $_SERVER['DOCUMENT_ROOT'].'/application/views/upload_images/';
move_uploaded_file($tmp_name, $path.$file_name);
$mail->setFrom($email, $name);
$mail->addAddress('abc@gmail.com','Mail Header');
$mail->addReplyTo($email, $name);
$mail->isHTML(true);
if($file_name != '' && $file_name != null){
$mail->AddAttachment($_SERVER['DOCUMENT_ROOT']."/application/views/upload_images/".$file_name,$file_name);
}
$mail->Subject = "Info From Web";
$mail->Body = '<strong>' .$msg . '</strong><br><br><h3>Regard : '.$name.'</h3>';
if ($mail->send()) {
echo "<script>alert('Email Sent Success!')</script>";
}
else{
echo "<script>alert('".$mail->ErrorInfo."')</script>";
}
You are trying to send from a gmail address without sending through a gmail server. This is forgery and will be blocked by google's SPF rules, as you're finding. If you want to send from a gmail address, you must send through a gmail server.
The real problem is that you are setting the from address to the submitter's address. Don't do that, as you'll have exactly the problems you're seeing. Put your own address in the from address, and put the submitter's address in a reply-to address. See the contact form example provided with PHPMailer for how to do this.
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.