firecat318 Posted May 4, 2008 Share Posted May 4, 2008 I have this code to send a sample message to an email: <?php $to = "[email protected]"; $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? Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/ 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(). Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-532579 Share on other sites More sharing options...
firecat318 Posted May 4, 2008 Author Share Posted May 4, 2008 Additional headers is optional though. Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-532705 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 Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-532707 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? Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-532754 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? Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-533011 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 ? Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-533042 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. Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-533088 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. Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-533168 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. Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-533180 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? Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-533190 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. Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-533191 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: [email protected]"; mail('firecat318', 'hello', 'just a test!', '$headers'); ?> Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-533873 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. Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-534025 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; } Link to comment https://forums.phpfreaks.com/topic/104032-mailing-error/#findComment-534040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.