I am creating a site for me only that will run from my server. I would like it to send me emails using php which is setup, but the emails go into my spam folder in gmail. How can I change this in gmail, not php, to send these emails to my inbox? I have tried using mail() and phpmailer().
Here is the Php code that I have.
$mail = new PHPMailer();
$body = "email from server - testing.";
$from = "email@mysite.com";
$email = "myemail@gmail.com";
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPDebug = 2;
$mail->SetFrom($from, "mysite.com");
$mail->AddReplyTo($from, "mysite.com");
$mail->Subject = "emails";
$mail->MsgHTML($body);
$address = $email;
$mail->AddAddress($address, "me");
// $mail->Send();
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I cannot see anything wrong with your code, since you seem to be setting the
Fromcorrectly. I would however suggest that you check the actual headers received by GMail (Show Originalunder message options on the email/message) and check that theFromheader is correct. An incorrect sender is a common cause of issues like this.As sarnold says above there is a degree of guess work involved, but I suggest you look at one or more of the following: