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.";

?>

30 REPLIES 30
Advocate V Advocate V
Advocate V

Re: PHP mail() not sending

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.

Re: PHP mail() not sending

 

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

Re: PHP mail() not sending

 

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!

Re: PHP mail() not sending

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.

mail is not going out, phpmailer smtp

mail is not going out, phpmailer smtp

Re: 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....

Helper I

Re: mail is not going out, phpmailer smtp

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

Employee
Employee

Re: mail is not going out, phpmailer smtp

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

Re: mail is not going out, phpmailer smtp

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.

 

Re: mail is not going out, phpmailer smtp

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.

Email Not Sending... AGAIN!

Id like to join the hordes of other customers begging you to sort out this issue with emails not sending. It's very upsetting that I, and we, are paying you for a service and that service is clearly faulty.

I (attempt) to use your service to run my business and your faulty product costs me time and money on a regular basis. I'll explain what the issue is, although I've already read many other posts of the same problem (bizarrely labelled 'solved' for some reason) that don't seem to provide any answer.

 

I press SEND. Nothing happens. Or, I press SEND, and it says SENDING, and nothing happens. Usually if I close and restart the browser I will be able to send one, maybe two emails, and then the problem returns. If it is a reply or back and forth thread then it NEVER works.

I am using the Workspace Email site through GoDaddy. I have tried numerous browsers. No change. I usually have to result to sending through Outlook on my phone which is not a reasonable fix as far as I am concerned. 

 

If you cannot suggest a fix for this problem asap then I would like to be informed and I will take my business elsewhere. 

Re: Email Not Sending... AGAIN!

I can't get the website to send me emails when potential clients are requesting information about services. I've called and have spent countless hours the last 2 weeks trying to get someone to help. When I'm on chat they say I need to talk to another departmentsl. When I call I'm on hold for so long and when I do speak to someone they say you need another department and transfer me to music for way too long over 36 minutes before I have to hang up because I alloted that amount of time so I can keep everything else going. But my website has a button for more information and that's how we get our clients and we can't right now. Hahhhhaaa I want to scream

Re: Email Not Sending... AGAIN!

I am experiencing this kind of problem on my apache it's not sending any email but when I check my status, the function run properly please help me..

New

Re: Unable To Open, Send, Receive Emails

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.

New

Re: Unable To Open, Send, Receive Emails

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?

Re: PHP mail() not sending

@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.

Re: PHP mail() not sending

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

Re: PHP mail() not sending

 

Re: PHP mail() not sending

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.

New

Re: Email Not Sending... AGAIN!

Their failure to resolve email issues to paying customers is why I will not be renewing my service.

 

 I've been complaining about the e-mail issues for a long time. You can't authenticate and successfully send mail via common PHP mailers with a lot of SMTP servers, including Outlook.com mail that they offer. The only e-mail account I've had any success with was gmail. If you choose to not use any authentication and use their "secureserver.net", e-mails work intermittently and are very slow to flow through.

 

Sure would be nice if they either resolved it on the back end or offered us a PHP class to work with that would report accurate error messages to us so we know how to proceed.

 

I'm willing to pay more to Alternative Network Solutions if it means I get functioning mail using PHP mailers. I have a few other accounts on here and host a few companies on here... I'll move them too.

 

-Andy

Re: Email Not Sending... AGAIN!

PHP Mailer isn't working at all! Please resolve this asap or else I would move my entire business to a different hosting provider! Thank you!

Re: PHP mail() not sending

Since there is no way to upvote other replies, I'll add my own.

 

PHP mail is sporadic at best.  I have a test script. I've run it 5 times over the course of 30 minutes.  I get two of the five emails delivered.  The other three?   Who knows.  Definitely not a business-grade email service.

 

I tried to get PHPMailer to work, but threw in the towel after hours of frustrating failures and phone calls.

 

Bottom line:  PLEASE fix the mail issues!

Solution

Re: PHP mail() not sending

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. 

instructions for sending emails from cPanel hosted domain

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.

Re: PHP mail() not sending

I'm having issues with GoDaddy not delivering my PHP sent mail. Of the dozen or so test emails sent, only one has come through.

 

I have now hosted the PHP script on another server I have access to, works every time.

New

Re: PHP mail() not sending

I'm tearing my hair out and really don't know what else to do. I want to try out the solution by king_sarge but not able to follow through. I am stuck at #5.

 

Where do you get to CPanel? I can't open mine, even using :2082 or cpanel.mydomain.com ...

Re: PHP mail() not sending

 

You are stuck with GoDaddy's own SMTPS servers: secureserver.net.

The only solution is to stop trying to use external SMTP, revert everything to original config and change your FROM address to something@secureserver.net.

If your company/site name is fruitandnut.com then make up something descriptive like:

fruitandnut@secureserver.net so that customers can still associate the email with your domain name. This approach should deliver your emails to inboxes, not spam.

Solution

Re: PHP mail() not sending

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.

Re: mail is not going out, phpmailer smtp

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!';
}

Re: mail is not going out, phpmailer smtp

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!