0
votes

i have trying to send email to reset user password using php mail() but its sends to spam folder in Gmail Account alone in yahoo mail i can get this mail inside inbox. i googled and seen that some of the people says to use smtp mail server via phpmailer.

i tried that too but i get same result as php mail() function did.. here my php mail() function code

$headers  = 'From: [email protected]' . "\r\n";
$headers .= 'Reply-To: '.$to.'';
$headers .= 'Subject: ' . $subject ." \r\n";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset="iso-8859-1"'. "\r\n";
@mail($to, $subject, $msg, $headers);

and php mailer smtp code

 date_default_timezone_set('Etc/UTC');

require_once 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'mydomain.us';

// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "[email protected]";

//Password to use for SMTP authentication
$mail->Password = "pass";

//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'sender name');

//Set an alternative reply-to address
$mail->addReplyTo('[email protected]', 'sender name');

//Set who the message is to be sent to
$mail->addAddress($to, 'John Doe');

//Set the subject line
$mail->Subject = $subject;

//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($msg);

//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';

//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
1
Whether your message ends up in spam doesn't have too much to do with how you send it, but more to do with what you send and what your recipients do with it. If recipients mark it as spam, before long, gmail will start doing that by default. Gmail has a history of marking pretty much everything as spam, and it's been getting worse.Synchro

1 Answers

0
votes

Your code looks good ok, but if your server's IP address has been added to spam blacklists that are used to filter spam, it wont matter how you send mail from your server.

Do a Google search for something like "mail server blacklist" and test your server's IP address to see if it has been blacklisted. If you are renting the server from a hosting company, changes are your IP address has been used by other people before you.

You can try creating a test Gmail account for your company and try sending out and e-mail from your server using that Gmail account with SMTP and see if the e-mail gets delivered. The e-mail would be sent from the Gmail server on your behalf.

Another option would be to use a Mailing API service like Mailgin.