0

I am facing an unexpected issue with a PHP mailfunction. The script sending email to all email address but not to my domain.

Suppose I send email to [email protected] it was received but when I send email to [email protected] it was not received.

I am using GoDaddy web hosting and PHP mail function. SMTP is also not working on GoDaddy server.

PHP code is as follows:

<?php

$to      = '[email protected]';
//$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$r  = mail($to, $subject, $message, $headers);
if($r) {
    echo 'mail sent';
}else {
    echo 'not sent';
}
die;

?>

And SMTP email via PHPMailer is not working as well:

<?php
echo "<pre>";

//die('ada');
require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer();
$mail->Host = "relay-hosting.secureserver.net"; // your SMTP Server
$mail->IsSMTP();
$mail->PORT = 465;
$mail->SMTPDebug=true;
$mail->SMTPAuth = true; // Auth Type
$mail->SMTPSecure = "ssl";
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->Sender = "[email protected]";
$mail->From = "[email protected]";
$mail->AddReplyTo("[email protected]");
$mail->FromName = "user ";
$mail->AddAddress("[email protected]");
$mail->IsHTML(true);
$mail->Subject = "Test subject";
$mail->Body='Test Subject';
$mail->WordWrap = 50;
if($mail->Send())
{
    echo"<script>alert('The Form has been posted ,Thank you');</script>"; 
}
else
{
    echo 'mail error';
}
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Nitin Kumar Soni
  • 198
  • 2
  • 16

1 Answers1

0

Suppose I send email to [email protected] it was received but when I send email to [email protected] it was not received.

I am using GoDaddy web hosting and PHP mail function. SMTP is also not working on GoDaddy server.

I doubt this has anything to do with the coding when using mail or PHPMailer. The thing is just because you send a mail, it doesn’t mean that the receiving end thinks the mail is valid. And chances are the receiving end—even if it is your domain—has decided a random e-mail sent off of a random server is simply SPAM.

I have posted a more detailed answer here, but when it comes to SPAM it basically boils down to this: Do you have an SPF (Sender Policy Framework) record setup for your domain? Do you also have a PTR (reverse DNS) record set for that domain?

If you do not have an SPF or PTR record, the chance of your message simply being flagged as SPAM is quite high.

If you are serious about sending mails off of your server, you need to at least get your SPF record & PTR record set.

Community
  • 1
  • 1
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103