vikela Posted October 29, 2009 Share Posted October 29, 2009 I would like to send an email using the php email() function then if it does execute i.e sends i would like to update a particular field in my db.however no matter how hard i try to the code seem to defy simply logic.here is the original code i have include_once("mailer.php"); $thesend=mail($toto1,$subject1,$message,$headers); if($thesend) { $mail_went=1; $_SESSION['msgstatus']= "Mail sent to ".$toto1."<br>"; }else{ $mail_went=0; $_SESSION['msgstatus']= "Mail send failure - message not sent <br>"; } the funny part is that the code executes the else and actually gives me the Mail send failure message yet i do receive the mail in my box???? However if i do change this to be like this include_once("mailer.php"); $thesend=mail($toto1,$subject1,$message,$headers); if(!$thesend) { $mail_went=1; $_SESSION['msgstatus']= "Mail sent to ".$toto1."<br>"; }else{ $mail_went=0; $_SESSION['msgstatus']= "Mail send failure - message not sent <br>"; } ........all works perfect what am i missing.The $message is an HTMl doc and the MIME and content-type are ok. Damn Link to comment https://forums.phpfreaks.com/topic/179470-email-logic-not-working/ Share on other sites More sharing options...
Bricktop Posted October 29, 2009 Share Posted October 29, 2009 Hi vikela, Just put the mail() funtion directly into the if statement. Change your code to read: include_once("mailer.php"); if(mail($toto1,$subject1,$message,$headers)) { $mail_went=1; $_SESSION['msgstatus']= "Mail sent to ".$toto1."<br>"; }else{ $mail_went=0; $_SESSION['msgstatus']= "Mail send failure - message not sent <br>"; } Hope this helps. Link to comment https://forums.phpfreaks.com/topic/179470-email-logic-not-working/#findComment-946904 Share on other sites More sharing options...
vikela Posted October 29, 2009 Author Share Posted October 29, 2009 That was the first thing before the $sendto and got no joy.. Link to comment https://forums.phpfreaks.com/topic/179470-email-logic-not-working/#findComment-946907 Share on other sites More sharing options...
Bricktop Posted October 29, 2009 Share Posted October 29, 2009 Are you sure? The code I posted is the correct way to do it and should give the desired result. Link to comment https://forums.phpfreaks.com/topic/179470-email-logic-not-working/#findComment-946909 Share on other sites More sharing options...
vikela Posted October 29, 2009 Author Share Posted October 29, 2009 100% sure Link to comment https://forums.phpfreaks.com/topic/179470-email-logic-not-working/#findComment-946911 Share on other sites More sharing options...
Bricktop Posted October 29, 2009 Share Posted October 29, 2009 OK, just try the following code and report back with what gets echo'd to screen. include_once("mailer.php"); if(mail($toto1,$subject1,$message,$headers)) { $mail_went=1; $_SESSION['msgstatus']= "Mail sent to ".$toto1."<br>"; echo "Mail Sent!"; }else{ $mail_went=0; $_SESSION['msgstatus']= "Mail send failure - message not sent <br>"; echo "Mail Not Sent!"; } Link to comment https://forums.phpfreaks.com/topic/179470-email-logic-not-working/#findComment-946913 Share on other sites More sharing options...
vikela Posted October 29, 2009 Author Share Posted October 29, 2009 Mail not Sent! obvious Link to comment https://forums.phpfreaks.com/topic/179470-email-logic-not-working/#findComment-946918 Share on other sites More sharing options...
Bricktop Posted October 29, 2009 Share Posted October 29, 2009 Did the mail arrive as you mentioned before, or has the mail not actually arrived either? Add some error reporting to your script, run it and then report back: ini_set ('display_errors', 1); error_reporting (E_ALL & ~ E_NOTICE); include_once("mailer.php"); if(mail($toto1,$subject1,$message,$headers)) { $mail_went=1; $_SESSION['msgstatus']= "Mail sent to ".$toto1."<br>"; }else{ $mail_went=0; $_SESSION['msgstatus']= "Mail send failure - message not sent <br>"; } Link to comment https://forums.phpfreaks.com/topic/179470-email-logic-not-working/#findComment-946919 Share on other sites More sharing options...
Bricktop Posted October 29, 2009 Share Posted October 29, 2009 Also, how are you running your PHP install? Is it running locally from a WAMP/XAMPP installation? Is it externally hosted? Is it a CGI build? What platform is it running on (Windows/Linux)? Link to comment https://forums.phpfreaks.com/topic/179470-email-logic-not-working/#findComment-946923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.