/    Sign up×
Community /Pin to ProfileBookmark

Mail or session error?

In following code
$email_addr = ‘[email protected]‘; Works and sends email to my email address. But
$emailAddr2 = “”.$_SESSION[“ThisEmp”][“email”].””; Doesn’t work. I tried by removing “” also.

And echo ”.$emailAddr2; echos my email address. That means session variable is set. What might be reason?

And catch block is not getting executed it is not throwing any error also.

Thank you.
——————————–

$headers = “From: [email][email protected][/email]“;

$emltpl = ‘templates/email_new_employer.txt’;

$template = file_get_contents($emltpl);

$tp1 = str_replace(‘<username>’, $_SESSION[“ThisEmp”][“username”], $template);
$tp2 = str_replace(‘<password>’, $_SESSION[“ThisEmp”][“email”], $tp1);
$tp3 = str_replace(‘<empname>’, $_SESSION[“ThisEmp”][“empname”], $tp2);

echo ’email template’.$tp3;

$email_addr = ‘[email protected]‘;
$emailAddr2 = “”.$_SESSION[“ThisEmp”][“email”].””;

echo ”.$emailAddr2;

try{
mail(”.$emailAddr2.”, ‘Your account information session’, $tp3, $headers);

}

catch (Exception $x)
{
echo “There is error in sending mail”. $x->getMessage( );

exit();
}

mail($email_addr, ‘Your account information’, $tp3, $headers);

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 09.2008 — mail() does not throw exceptions, so there will be nothing to catch even if it fails. Either simply check the return value to see if it's false, or if you need to throw an exception for some reason, then you'll have to throw your own.
Copy linkTweet thisAlerts:
@SH100authorJun 09.2008 — I don't know why but when I copied session variable to local variable, It was getting value inside Quotes that was causing problem. Surprisingly mail() was still returning 1 but not sending email. So solution str_ireplace("'", "", $emailAddr3) worked for me. And now it's sending email.

Thank you for answering.


-------------------------------------

$emailAddr2 = $_SESSION["ThisEmp"]["email"];

$emailAddr3 = $emailAddr2;

try{
$MailSend1 = mail(str_ireplace("'", "", $emailAddr3), 'Your account information session', $tp3, $headers);
}

catch (Exception $x)
{
echo "There is error in sending mail". $x->getMessage( );

exit();
}
×

Success!

Help @SH100 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...