cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution

PHP mail() not sending

 

I am creating a simple form to capture email addresses for a newsletter.  The form & data entry work fine (I see them in the database) -- but I never receive the email. 

 

Does GoDaddy block me from sending these kinds of emails through PHP?  Any ideas?  Any help is appreciated.

 

Here is the code:

 

<?php

// database connection & data insert above

//email registeration confirmation

$mysite = "SC Sports";
$webmaster = "Webmaster @ SC Sports";
$myemail = webmaster+(myrealemail).com;

$subject = "Weekly Sports Updates from $mysite";
$message = "<html><body><br>

Thank you for your interest in our weekly updates. You will now be receiving them by email.<br><br>

If you no longer wish to receive these emails, please send an email to webmaster @ SC sports.com.<br><br>

Have Fun!<br><br>

$webmaster

</body></html>";


$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: SC SPORTS <DONOTREPLY@example.com>' . "\r\n";

mail($email, $subject, $message, $headers);

echo "A confirmation has been sent to your email address.";

?>

2 ACCEPTED SOLUTIONS

This was marked as solved, but the posted solution didn't work for me. I was able to solve my issue, so I'll share what I did. If you use the Office365 email account purchased with your domain, and you want the php in your code to send emails to that address via a form, then you have to make sure the MX entry on the domain server matches the MX entry in on the hosting server. Here's what you do:

 

1. Login to your GoDadday account, and click on "My Products"

2. Find your target domain and click on the "DNS" button

3. Scroll down until you see the entry row for "MX" and find the "Value" column

4. Copy this part of the entry to your clipboard. (should be some kind of web address)

5. Open a new tab and login to cpanel (...yourdomain/cpanel)

6. Scroll to the bottom to find the "Email" section. Click "MX Entry"

7. Make sure "Remote Mail Exchanger" radio button is selected. If not, select it and click change. (*** This is important before changing the MX entry***)

8. At the bottom,under "MX Records", click edit (or add a new one if it doesn't already exist).

9. Replace the "Destination" by pasting what you copied from the GoDaddy DNS manager.

10. Click "Edit". Now you're done.

 

The "MX record" should now match whatever was in the "Value" column of the MX entry from the DNS manager, and your form should work. I would imagine the same thing would work for any remote email server (e.g. Google), as long as the MX entries match. I hope this helps the rest of you who still can't get the email form on your site to work. 

View solution in original post

I've found this article and thought I would add a bit more clarity on this issue for anyone else who finds it. This all depends on who is managing your email. A good tip to figure this out is to visit https://who.is. Enter your domain name into the text box and click the search button. This will initially bring up your WHOIS information. Under the domain name, you have four tabs (Whois, History, DNS Records and Diagnostics). Select "DNS Records". Now look for any records that have the "MX" type. Note down the domain name specified under "Content". This is telling you who is managing your email.

 

If it's GoDaddy, they should be more than capable to help you out.

 

If it's managed by someone else then you will need to contact GoDaddy to let them know, so they can ensure your hosting is pointing to the "Remote Mail Exchanger" and not the "Local Mail Exchanger".

 

Alternatively, if you have cPanel, you can do this yourself via the cPanel dashboard. Go to the dashboard, select "MX Entry" under the "Email" section. Under "Email Routing", select "Remote Mai Exchanger" and click "Change".

 

That should cover most scenarios here.

View solution in original post

30 REPLIES 30
Advocate V Advocate V
Advocate V

I remember struggling with this myself and I think what might be needed is to add the To field to the headers.

 

$headers .= "To: $email\r\n";

Also, on many servers, the From field has to contain an email address that actually exists in the account.  I think this depends on what kind of hosting plan you have but it couldn't hurt to define one of your free accounts as noreply@whatever.com and set it's mailbox size to 1MB.

 

Keep on Coding!
Mark Cicchetti - There are 10 kinds of people... those who understand binary and those who don't.

 

Thanks -- I'll keep playing around with it.

 

I finally got it fixed by calling GoDaddy support to ask if they needed to do something on their side.  He fixed a setting in my "MX entry"(?) and now it works!

I had the same experience. What I was told was that GoDaddy has two different mail servers, Workspace and the cPanel server. GoDaddy has to turn on their MX entries (don't ask me what that is) so that the mail will be sent through the cPanel server. 

 

After I called them and told them the issue I was having, they helped me out and it started working within 30 minutes. You can also forward the e-mails to another domain, if you wish.

@scurrynWhat did he change to get it working, I am getting the same problem too and I wonder what needs to be change in order for it work.

I had a similar issue but when i used the localhost server it worked perfectly

 

$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = "localhost";
$mail->Port = "25";
$mail->SMTPSecure = "none";
$mail->SMTPAuth = false;
$mail->Username = "#####";
$mail->Password = "####";

 

#KeepOnCoding

 

I've recently run into this same issue.  The PHP mail function sometimes works and sometimes does not.  I have spoken with three different tech support employees.  All three sent a test email through a piece of short code (condescendingly worded "Welcome to the land of the future!") that functioned.  However, every single time that I told them that my code works only sporadically, I was told it was a problem with my code.  Mind you, this is code that has worked flawlessly for three years until suddenly this month.  GoDaddy has a real problem on their hands if they cannot provide this simple functionality.  Instead of carrying techs who do nothing but blame customers, they better fix this or we are taking our business elsewhere.

I am looking for FULL instructions on how to send emails from a domain using cPanel hosting and written in PHP. I refer to the comments in the web page :

 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

under GoDaddy. This gives a partial solution but is incomplete.

Surely there must be someone in GoDaddy who can provide more detail instructions.

I've found this article and thought I would add a bit more clarity on this issue for anyone else who finds it. This all depends on who is managing your email. A good tip to figure this out is to visit https://who.is. Enter your domain name into the text box and click the search button. This will initially bring up your WHOIS information. Under the domain name, you have four tabs (Whois, History, DNS Records and Diagnostics). Select "DNS Records". Now look for any records that have the "MX" type. Note down the domain name specified under "Content". This is telling you who is managing your email.

 

If it's GoDaddy, they should be more than capable to help you out.

 

If it's managed by someone else then you will need to contact GoDaddy to let them know, so they can ensure your hosting is pointing to the "Remote Mail Exchanger" and not the "Local Mail Exchanger".

 

Alternatively, if you have cPanel, you can do this yourself via the cPanel dashboard. Go to the dashboard, select "MX Entry" under the "Email" section. Under "Email Routing", select "Remote Mai Exchanger" and click "Change".

 

That should cover most scenarios here.

View solution in original post

mail is not going out, phpmailer smtp

Sorry for short message, actually I typed 3-4 times, but sending failed.

I want to send a mail from php

I am using phpmailer

connecting to smtp server at 465, with myuser@mydomain.com

 

I am able to send mails to accounts on same domain

but not to outsiders GMail, Rediff....

Hello,

 

This may seem like a silly question but I promise there is method in my madness.

 

Are you the developer of this particular file / website that is not sending the email and is this a PHP file that you or your developer wrote yourself or is there some sort of web application plugin that is used with a program such as Wordpress or Joomla?

 

The reason I ask is that if this is a file you have written to work with the PHP Mail application on the server, you could dump all the data just before it posts and make sure that all the required elements of your script are there; also any errors that might be happening in the finalisation are likely to be dumped as well and might give some light to where the error is occurring in your program.

 

 

 

Warm Regards,

Wade Hextell

wadehextell at gmail.com

https://au.linkedin.com/in/wadehextell

Thanks for reply @auswade.

Below is my code and configuration I tried.

All other cases

     SMTP Connect fail

Except 

    $mail->Host = 'sg2plcpnl0221.prod.sin2.secureserver.net';

    $mail->Username = myuser@pravinc.in;  
    $mail->Password = mypassword;           

Mail is going to otheruser@pravinc.in but not to otheruser@gmail.com

 

   $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SM TP
    $mail->SMTPDebug = 1;  // debugging: 1 = errors and messages, 2 = messages only

    $mail->SMTPAuth = true;  // authentication enabled

   

   $mail->SMTPSecure = 'tls';
    $mail->Port = 587;
    

   $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;


    $mail->Port = 25;
    

    $mail->Host = 'smtp.gmail.com';
    $mail->Username = myuser@gmail.com;  
    $mail->Password = mygmailpassword;           
    

    $mail->Host = 'relay-hosting.secureserver.net';
    $mail->Host = 'smtpout.asia.secureserver.net';
    $mail->Host = 'localhost';
    $mail->Host = 'sg2plcpnl0221.prod.sin2.secureserver.net';

    $mail->Username = myuser@pravinc.in;  
    $mail->Password = mypassword;           
  

    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo;
        return false;
    } else {
        $error = 'Message sent!';
        return true;
    }

'PRIMARY'2016-11-30 15:50:03 CLIENT -> SERVER: EHLO pravinc.in 2016-11-30 15:50:03 CLIENT -> SERVER: AUTH LOGIN 2016-11-30 15:50:03 CLIENT -> SERVER: ZmxvY2tAcHJhdmluYy5pbg== 2016-11-30 15:50:03 CLIENT -> SERVER: ZmJ1enox 2016-11-30 15:50:04 CLIENT -> SERVER: MAIL FROM: 2016-11-30 15:50:04 CLIENT -> SERVER: RCPT TO: 2016-11-30 15:50:04 CLIENT -> SERVER: DATA 2016-11-30 15:50:04 CLIENT -> SERVER: Date: Wed, 30 Nov 2016 15:50:03 +0000 2016-11-30 15:50:04 CLIENT -> SERVER: To: chaudhary.pravin@gmail.com 2016-11-30 15:50:04 CLIENT -> SERVER: From: Pravin 2016-11-30 15:50:04 CLIENT -> SERVER: Subject: Hi 2016-11-30 15:50:04 CLIENT -> SERVER: Message-ID: <29acea86a97c5823fa7f7f818818e38c@pravinc.in> 2016-11-30 15:50:04 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.16 (https://github.com/PHPMailer/PHPMailer) 2016-11-30 15:50:04 CLIENT -> SERVER: MIME-Version: 1.0 2016-11-30 15:50:04 CLIENT -> SERVER: Content-Type: text/plain; charset=iso-8859-1 2016-11-30 15:50:04 CLIENT -> SERVER: 2016-11-30 15:50:04 CLIENT -> SERVER: Hello 2016-11-30 15:50:04 CLIENT -> SERVER: 2016-11-30 15:50:04 CLIENT -> SERVER: . 2016-11-30 15:50:04 CLIENT -> SERVER: QUIT Message sent!

Please help.

 

Hello @PravinC and welcome to the community! In addition to the suggestions @auswade provided, if you're using SMTP for sending mail then please ensure the correct relay server and port are configured in your settings, which would be relay-hosting.secureserver.net using port 25.

 

Naterx - GoDaddy | Community Moderator
24/7 support available at x.co/247support

I'm also having this issue.  Most emails are getting 'lost/blocked'.  Php or SMTP.  My code (from Zencart) delivers to the SMTP server and nothing is received externally.  Using relay-hosting.secureserver.net and port 25.  Doesn't matter if I pass credentials or not.  It's been working for years without credentials...lately it's very sporadic, but seems to be increasing in failures.

i have the same problem sir, i wrote this code a week ago i'm using phpmailer too and its working well to my localhost but after i upload to godaddy the error message appear "Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting"

 

PLEASE HELP

 

here's my code


$to = $_POST['emailto'];
$_subject = $_POST['subject'];
$_message = $_POST['msg'];
$mail = new PHPMailer;

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication

$mail->Username = 'mygmail@gmail.com'; // SMTP username
$mail->Password = 'mygmailpassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to

$mail->setFrom('sample@gmail.com', 'sample@gmail.com'); // sender
$mail->addAddress($to); // Add a recipient
$mail->isHTML(true);

 

$mail->Subject = $_subject;
$mail->Body = $_message;

if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent!';
}

Discalimer: I'm NOT a PHP expert.

 

Hi Dominique - your code looks sound. Try omitting the leading underscores before "subject" and "message". It's subtle, but I remember something about leading underscores being an outdated practice in modern PHP. I hope this helps!

So now my php email function from my website isn't  working meaning that we're missing order notifications coming from the website.

 

This needs to be fixed asap.

Tested my server and it would appear that the mail system is working.

 

I'm still getting emails turning up 1-2 days late from various senders and I've tried deleting about half a dozen spammy emails today and they just keep showing up.  Why can't I get rid of them?