简体   繁体   中英

php mail() - delivered as spam(using php mailer library)

require("class.phpmailer.php");

$mail = new PHPMailer()

$mail->From = "sender@gmail.com";
$mail->AddAddress("recipient@gmail.com");                 // name is optional
$mail->AddReplyTo("sender@gmail.com");

$mail->WordWrap = 50;                                    // set word wrap to 50 characters
$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";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

I don't know what headers i need to add, to send the email NOT as spam, and how can i use this?

//$mail->IsSMTP(); // is this necessary?
//$mail->Host = "some host ip";  // what i need to write here?
//$mail->SMTPAuth = true;     // is this necessary to send email NOT as spam?
//$mail->Username = "test";  // and this?
//$mail->Password = "secret"; // and this?

for some time googling , I didn't find any clear information about how to send an email NOT as spam... any ideas?

Unfortunately, the mail server you're currently using has probably been sending out junk in the past. Are you on a shared hosting plan? Because if you are, it's possible that other websites on the same hosting plan as you have been sending out spam/suspicious/junk emails via the same the mail server. To try and avoid this issue, you should try and not use spoofed FROM headers. Unfortunately, that's unlikely to do anything if Gmail etc have already identified the mail server you're using as an origin for spam.

Make sure the From header really matches e-mail address available on the server you're sending it from - spoofing From headers (sending from host.com but saying it's from abc@otherhost.com) raises your spam score.

Also - is the HTML page well-formed to prevent being marked as spam? For example, does it have an unsubscribe link? Or isn't the subject of that mail something like "free something for you"?

I am not sure but see below URL I think it is very help full to you.

How do I prevent mails sent through PHP mail() from going to spam?

How do I prevent mails sent through PHP mail() from going to spam?

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