Go Back   HostGator Peer Support Forums > HostGator Peer Support Forums > Shared Hosting Support

Notices

Reply
 
Thread Tools
  #1  
Old 04-16-2007, 06:52 PM
icon icon is offline
Hatchling Croc
 
Join Date: Apr 2007
Posts: 1
Default mail() not sending mail in PHP script

I have a dedicated server with EV1 that I love and got a reseller account here to test scripts.

I seem to be having a problem with none of my scripts sending out mail using the mail() function. These work fine on my server, but just not on my hostgator account. Here is the basic of what I am doing. Variables are from an included config file and from $_post. Doesn't seem to have a problem grabbing the variables, just will not mail out. Server restriction perhaps?

$subject = "$site_name Contact Us";
$message = "Name: $name\n\n";
$message .= "Comments: $comments\n\n";
$message .= "$site_url/\n";
$mailheaders = "From: $_post['email']";";
$mailheaders = "Reply-To: $_post['email']";

mail($site_email,$subject,$message,$mailheaders);
Reply With Quote
  #2  
Old 04-16-2007, 08:13 PM
PsiPro PsiPro is offline
King Croc
 
Join Date: Nov 2005
Posts: 812
Default Re: mail() not sending mail in PHP script

There is a limit to the numer of e-mails you can send out per hour, are you exceeding that limit?

Edit:

Your code seems to be wrong, the syntax to mail() is

mail ( $to, $subject, $message, $additional_headers, $additional_parameters)

Are you sure $to ( in your case $site_email is your visitor's e-mail address)
__________________
http://www.theaquariumwiki.com/

Last edited by PsiPro; 04-16-2007 at 08:15 PM.
Reply With Quote
  #3  
Old 04-19-2007, 06:48 AM
Evick Evick is offline
Hatchling Croc
 
Join Date: Apr 2007
Posts: 1
Default Re: mail() not sending mail in PHP script

I also am having issues with this. I have had my mail script working on multiple sites I run on my reseller package for some time now, just recently it came to my attention that it was not working. Nothing has changed with the code in the time the script has been up. Also the script works fine on other servers not hosted with hostgator. As for exceeding my hourly limit for sending mail, this I believe is not the issue, at least not to my knowledge, I can send mail at any time with outlook, just not via the script. Has something changed on our servers? Is there a new suggested way to take care of this?
Reply With Quote
  #4  
Old 04-20-2007, 04:26 AM
hbird hbird is offline
Hatchling Croc
 
Join Date: Apr 2007
Posts: 11
Default Re: mail() not sending mail in PHP script

Hi, and I have had an account for only 2 days, and I'm experiencing the same issues as described above. I find that IPB (2.2) is failing to send email messages, and I even verified this by sending myself an email through the forums. I haven't tried sending mail through an email account with roundcube yet, though.
Reply With Quote
  #5  
Old 06-18-2007, 08:21 AM
GatorJim's Avatar
GatorJim GatorJim is offline
HostGator Staff
 
Join Date: Apr 2007
Posts: 80
Default Re: mail() not sending mail in PHP script

Here is how I did it.

$message = "This is the body of the email.\n\n";
$message .= "More body: probably a variable.\n";
$headers="From: someone@domain.com\r\n";
$subject = "This goes in the subject line of the email!!!";
$to_address = "email@mydomain.com";
$mailsend=mail("$to_address","$subject","$message" ,"$headers");

Works great for me.

*BTW - I use my own postmaster email as the From field and include the visitors email inside the body of the message. If you try to use the visitors email address as part of the headers then it could be blocked by their SPF record. (I can only see this as forging an email header so I just don't do it, but a lot of script writers do.)

Last edited by GatorJim; 06-18-2007 at 08:24 AM.
Reply With Quote
  #6  
Old 06-18-2007, 11:17 PM
Impavidus Impavidus is offline
Junior Croc
 
Join Date: Feb 2006
Posts: 155
Default Re: mail() not sending mail in PHP script

There are also problems with the following:

$mailheaders = "From: $_post['email']";";
$mailheaders = "Reply-To: $_post['email']";

It should read like this:

$mailheaders = "From:" . $_post['email'] . "\r\n";
$mailheaders .= "Reply-To:" . $_post['email'];
Reply With Quote
  #7  
Old 07-16-2008, 01:47 AM
Rowshan Rowshan is offline
Hatchling Croc
 
Join Date: Mar 2008
Posts: 7
Default Mail(): Return True but cannot send

Dear Friends,
I have a script in my website for sending feedback.
It returns TRUE for mail() but it can't send email to receiver at all.
Why?
I have joomla nd drupal in my host but they work good and send emails successfully.
-----------------------------------
My script is as following:

$to = "admin@domain.org";
$sender = $_POST['email'];
$headers = 'From:'.$sender."\r\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/HTML; charset=utf-8'."\r\n";
$body = "<html><body style='font-family: Tahoma;'>".htmlspecialchars(nl2br($_POST['msg']))."<br><font color='#0000FF'>".$_POST['email']."</font></body></html>";
$send=mail($to, "WadiOnline News (Feedback) > ".$subject, $body, $headers);
if($send){
echo 'Thanks for your feedback!';
} else {
echo 'An Error happened in sending.';
}

Waiting for your ehlp.
Reply With Quote
  #8  
Old 07-16-2008, 06:35 AM
Arctic Fire Arctic Fire is offline
Hatchling Croc
 
Join Date: Jul 2008
Location: /dev/null
Posts: 35
Default Re: mail() not sending mail in PHP script

This doesn't really help yalls' problems but at my old host, the mail never worked. It would work on other hosts, I got people to try it for me. But it would never send, though it returned true. I think it might have when I first went to them.
__________________

Reply With Quote
  #9  
Old 07-16-2008, 06:51 AM
ghpk ghpk is offline
King Croc
 
Join Date: Nov 2006
Posts: 1,245
Default Re: mail() not sending mail in PHP script

Quote:
Originally Posted by Arctic Fire View Post
This doesn't really help yalls' problems but at my old host, the mail never worked. It would work on other hosts, I got people to try it for me. But it would never send, though it returned true. I think it might have when I first went to them.
your old host may have been blocking the nobody user (the user under which php runs on the server) and only option on such a server would be to use a SMTP class with your script.

However as hostgator uses phpsuexec, where users' scripts are run as the user account the mail() functions works fine.
Reply With Quote
  #10  
Old 07-16-2008, 05:41 PM
slapshotw's Avatar
slapshotw slapshotw is offline
Veteran Croc
 
Join Date: Jun 2006
Posts: 5,164
Default Re: mail() not sending mail in PHP script

Rowshan-- try the simple case first. Remove the extra headers and large body, and just do a "Hello World" with the required parameters. Does that work?
__________________
Follow me on Twitter! http://twitter.com/mrw
Reply With Quote
  #11  
Old 07-17-2008, 02:31 AM
Rowshan Rowshan is offline
Hatchling Croc
 
Join Date: Mar 2008
Posts: 7
Default Re: mail() not sending mail in PHP script

Dear Friends,
Thanks!
I check it with a small script as following but nothing:

<?php
// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail('admin@domain.org', 'My Subject', $message);
?>

Maybe the problem is related to something else.
drupal and joomla are using from mail() with header FROM. But they do that right.
Why?

Best Regards
Reply With Quote
  #12  
Old 07-17-2008, 02:55 AM
striddy's Avatar
striddy striddy is offline
Veteran Croc
 
Join Date: Mar 2008
Location: /home/australia/earth
Posts: 4,093
Default Re: mail() not sending mail in PHP script

Quote:
Originally Posted by Rowshan View Post
<?php
// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail('admin@domain.org', 'My Subject', $message);
?>
I copied / pasted this exact code to a .php file and it worked fine for me.
__________________
- David
Reply With Quote
  #13  
Old 07-17-2008, 03:10 AM
Rowshan Rowshan is offline
Hatchling Croc
 
Join Date: Mar 2008
Posts: 7
Default Re: mail() not sending mail in PHP script

So, Where is the problem?
I contacted to support Dep of hostgator and they said me:

The issue here is that you are trying to send email from an email address that is not hosted on the server. Please change your script to not set a from address and the mail will send.

But as you can see in the above script. It doesn't has FROM.
Please help me.
Thanks

Last edited by Rowshan; 07-17-2008 at 03:14 AM.
Reply With Quote
  #14  
Old 07-17-2008, 05:38 AM
eLIANT eLIANT is offline
King Croc
 
Join Date: Apr 2005
Posts: 1,075
Default Re: mail() not sending mail in PHP script

In my script, I had to change the path to the sendmail program to look like this:
Code:

$mailprog = '/usr/sbin/sendmail -i -t';


The -t was not present in the original version, and HG staff directed me to add it.
__________________

eLIANT Technology Services
(site feedback welcome)
Reply With Quote
  #15  
Old 07-17-2008, 08:55 AM
slapshotw's Avatar
slapshotw slapshotw is offline
Veteran Croc
 
Join Date: Jun 2006
Posts: 5,164
Default Re: mail() not sending mail in PHP script

Quote:
Originally Posted by Rowshan View Post
The issue here is that you are trying to send email from an email address that is not hosted on the server. Please change your script to not set a from address and the mail will send.
Did they see your new script? There's no from address being set at all. Tell them that.
__________________
Follow me on Twitter! http://twitter.com/mrw
Reply With Quote
  #16  
Old 08-15-2008, 03:45 PM
shark shark is offline
Hatchling Croc
 
Join Date: Aug 2008
Posts: 2
Default Re: mail() not sending mail in PHP script

I am having the same problem. I don't see an answer here.

My hello world.

mail('tom@anotherdomain.com', 'hello world', 'hello world');
Reply With Quote
  #17  
Old 08-15-2008, 03:58 PM
shark shark is offline
Hatchling Croc
 
Join Date: Aug 2008
Posts: 2
Default Re: mail() not sending mail in PHP script

Quote:
Originally Posted by shark View Post
I am having the same problem. I don't see an answer here.

My hello world.

mail('tom@anotherdomain.com', 'hello world', 'hello world');
Never mind!

I realized that I was sending to a domain that I have set up hosting for, but have not moved over yet. I bet the DNS servers have the domain set up so the mail was not being sent to the correct place. When I changed the to address it worked fine.
Reply With Quote
  #18  
Old 08-22-2008, 08:40 PM
stiill stiill is offline
Hatchling Croc
 
Join Date: Jan 2007
Posts: 3
Default Re: mail() not sending mail in PHP script

Same problem. My awesome script:

$retval = mail("myaddress@example.com", "testsub from testmailer", "testmsg from testmailer", "From:anotheraddress@example.com\r\n");
echo $retval;


It echoes 1. In this example, "anotheraddress@example.com" is a valid, functioning email address on the domain on which I'm running the script. Hostgator hosts it.
Reply With Quote
  #19  
Old 08-22-2008, 08:59 PM
stiill stiill is offline
Hatchling Croc
 
Join Date: Jan 2007
Posts: 3
Default Re: mail() not sending mail in PHP script

Hmm, looks like mail was down for a while. Changed nothing, now it's working. Hooray!
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 01:30 PM.