firecat318 Posted May 4, 2008 Share Posted May 4, 2008 I have this code to send a sample message to an email: <?php $to = "firecat318@gmail.com"; $subject = "hello"; $message = "this is just a random test"; $mail = mail($to, $subject, $message); if(!$mail) { die("There was a problem when mailing!"); } else { echo "Thank you for sending your mail!"; } ?> When I run the script, it says there was an error mailing. Is there anything in particular that I need to set up on my host so that it allows me to send mails? Quote Link to comment Share on other sites More sharing options...
pwes24 Posted May 4, 2008 Share Posted May 4, 2008 The mail function takes 4 arguments like this: mail($to, $subject, $message, $headers) . Please refer to the php documentation for further explanation. Just search mail(). Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 4, 2008 Author Share Posted May 4, 2008 Additional headers is optional though. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 Are you sure you have a mail server that PHP can find on your server? T.T Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 4, 2008 Author Share Posted May 4, 2008 I dont know... like I said, I haven't set anything up yet. I do I go about that? Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 4, 2008 Author Share Posted May 4, 2008 Do I need to setup something special to be able to send emails? Quote Link to comment Share on other sites More sharing options...
ady01 Posted May 4, 2008 Share Posted May 4, 2008 Are you running this script on your own server or are you using a hosted soluting such as lycos ? Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 4, 2008 Author Share Posted May 4, 2008 I'm using godaddy, so its not my server. Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 5, 2008 Author Share Posted May 5, 2008 OMG I can't find an answer anywhere. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 5, 2008 Share Posted May 5, 2008 I'm using godaddy, so its not my server. I'm using godaddy too.. works for me. Did you buy linux or windows hosting? The php mail() function is for linux only. Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 5, 2008 Author Share Posted May 5, 2008 I got the windows hosting. is there anyway to switch it without paying? Quote Link to comment Share on other sites More sharing options...
trq Posted May 5, 2008 Share Posted May 5, 2008 The php mail() function is for linux only. No it is not. You will however need to at least set a From header under windows. Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 5, 2008 Author Share Posted May 5, 2008 I've added a from header, but it still won't send. <?php $headers = "From: subbyaccount@gmail.com"; mail('firecat318', 'hello', 'just a test!', '$headers'); ?> Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 6, 2008 Author Share Posted May 6, 2008 I'm very quite stumped. Is there something special that I need to setup in my hosting that will allow me to send emails, or will it work without anything special setup? I'm using godaddy windows hosting. I've tried lots of different variations of this code but it won't work. I'm just wondering if there is something I'm not getting that is causing the mail not to be sent. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 6, 2008 Share Posted May 6, 2008 *Cough* Switch to Linux because Windows sucks *Cough* I did a Google search for "php mail windows godaddy" and got this *sigh*: You need to use PEAR Mail for it to work. Here's an example. require_once "Mail.php"; function emailHtml($from, $subject, $message, $to) { $host = "localhost"; $username = ""; $password = ""; $headers = array ('MIME-Version' => "1.0", 'Content-type' => "text/html; charset=iso-8859-1;", 'From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => false)); $mail = $smtp->send($to, $headers, $message); if (PEAR::isError($mail)) return 0; else return 1; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.