Jump to content

Email logic not working


vikela

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.