cromagnon Posted December 28, 2007 Share Posted December 28, 2007 I am trying to send an email based on a form. I am using this script, but I do not get any emails: <?php $to = "[email protected]"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> What is the problem? any other ways to send mails via PHP? Thanks! Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/ Share on other sites More sharing options...
Daniel0 Posted December 28, 2007 Share Posted December 28, 2007 Any errors? Does it say sent and you don't get the mail or does it say failed when you run the script? Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424685 Share on other sites More sharing options...
revraz Posted December 28, 2007 Share Posted December 28, 2007 PHP will usually error if you dont have a FROM header, unless that is set in your PHP.INI Also, some services deny the mail, like AOL. Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424688 Share on other sites More sharing options...
cromagnon Posted December 28, 2007 Author Share Posted December 28, 2007 Hmm, thanks. I do not use AOL and I just added a "from" like this: <?php $to = "[email protected]"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $from = "Sandra Sender <[email protected]>"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> Stil no mail in my inbox. The script comes on a page after a form. URL like this http://www.my-site/send1.php?websted=hi&[email protected] But that should not cause any problems? Any other way to send a mail via PHP? Best Cromagnon Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424704 Share on other sites More sharing options...
revraz Posted December 28, 2007 Share Posted December 28, 2007 You need to add the $from to your mail() function and format it like $from = "FROM: Sandra Sender <[email protected]>"; if (mail($to, $subject, $body, $from)) Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424710 Share on other sites More sharing options...
cromagnon Posted December 28, 2007 Author Share Posted December 28, 2007 Wouw, now its working! You guys are genius Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424727 Share on other sites More sharing options...
Daniel0 Posted December 28, 2007 Share Posted December 28, 2007 You need to add the $from to your mail() function and format it like $from = "FROM: Sandra Sender <[email protected]>"; if (mail($to, $subject, $body, $from)) I know I'm just being picky, but the fourth argument isn't a from argument but a header argument and what you do is that you are adding the From header. Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424728 Share on other sites More sharing options...
revraz Posted December 28, 2007 Share Posted December 28, 2007 Never said it was a from arguement, I just said FROM was required. You need to add the $from to your mail() function and format it like $from = "FROM: Sandra Sender <[email protected]>"; if (mail($to, $subject, $body, $from)) I know I'm just being picky, but the fourth argument isn't a from argument but a header argument and what you do is that you are adding the From header. Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424730 Share on other sites More sharing options...
Daniel0 Posted December 28, 2007 Share Posted December 28, 2007 You implied it with your code, but whatever. Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424731 Share on other sites More sharing options...
revraz Posted December 28, 2007 Share Posted December 28, 2007 Look at his code above, all I did was include his variable in his mail() function, since he didn't. Sure I could have renamed his $from variable to $header, and then did it, but then it's just a name. I could have also provided a link to the mail() function and let him figure it out for himself too. You implied it with your code, but whatever. Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424732 Share on other sites More sharing options...
PFMaBiSmAd Posted December 28, 2007 Share Posted December 28, 2007 I'm still waiting to hear which one of the following messages are output by the code like Daniel0 asked in his first post in the thread - Message successfully sent! or Message delivery failed... Because that would help pin down where the problem is. Also, check your web server log for errors. Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424734 Share on other sites More sharing options...
Daniel0 Posted December 28, 2007 Share Posted December 28, 2007 I'm still waiting to hear which one of the following messages are output by the code like Daniel0 asked in his first post in the thread - Message successfully sent! or Message delivery failed... Because that would help pin down where the problem is. Also, check your web server log for errors. He did resolve his problem, but just didn't click "solved". Link to comment https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/#findComment-424744 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.