...

View Full Version : I get fatal mail error after PHP upgrade



zeroge
01-11-2010, 09:18 PM
Hi again

Now, upgraded to PHP2.2 I get all of a sudden a fatal mail error. Strange thing is, though ... All mail still get sent

It's a referral form. the form sends;

a notice to administrator displaying the referrer and the referral email addresses
a thank you letter to the referrer
an invitation letter to the invitees


here is the code I use

<?php

if ($_SERVER['REQUEST_METHOD'] != 'POST'){
header('Refresh: 0; URL=/index.html');
exit;
}

$mailto = "<me@my.com>";
$subject = "Tell a Friend Form from Survey";
$message = "Values submitted from the Tell a Friend form:";
$ack_subject = "Thank You";
$ack_message = "Thank you.\n";
$ack_message .= "Please.\n";
$ack_message .= "\n";
$ack_message .= "Are you!\n";
$ack_message .= "\n";
$ack_message .= "url";
$ack_message .= "\n";
$ack_message .= "To.\n";
$ack_message .= "\n";
$ack_message .= "url";
$ack_message .= "\n";
$ack_message .= "Enjoy.\n";
$ack_message .= "\n";
$ack_subject2 = "Business";
$ack_message2 .= Valid_Input($_POST['txtMessage']);
$ack_message2 .= "\n";
$ack_message2 .= "url";
$ack_message2 .= "\n";
$name = Valid_Input($_POST['Email']);
$email = !empty($_POST['Email']) && valid_email($_POST['Email']) ? $_POST['Email'] : $mailto;
foreach ($_POST as $key => $value){
if (!is_array($value)){
$message .= "\n".$key." : ".$value;
}
else{
foreach ($_POST[$key] as $itemvalue){
$message .= "\n".$key." : ".$itemvalue;
}
}
}
$header1 = "From: ".$name." <".$Email.">\n";
$header1 .= "Reply-To: ".$Email."\n";
$header2 = "From: ".$mailto."\n";
$header2 .= "Reply-To: ".$mailto."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/plain; charset=utf-8\n";
$header .= "Content-Transfer-Encoding: 8bit\n";
$header .= "X-Mailer: PHP v".phpversion();

$message .= "IP address:";
$message .= $_SERVER['REMOTE_ADDR'];
mail($mailto, $subject, stripslashes($message), $header1) or exit('Fatal Mail Error!');
mail($Email, $ack_subject, $ack_message, $header2) or exit('Fatal Mail Error!');
mail($EMailList, $ack_subject2, $ack_message2, $header1) or exit('Fatal Mail Error!');
mail($elista, $ack_subject2, $ack_message2, $header1);
mail($elistb, $ack_subject2, $ack_message2, $header1);

function Valid_Input($data){
list($data) = preg_split('/\r|\n|%0A|%0D|0x0A|0x0D/i',ltrim($data));
return $data;
}
function Valid_Email($data){
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
if (preg_match($pattern,$data)){
return $data;
}
else{
return $GLOBALS['mailto'];
}
}
?>

Thank you very much

zeroge
01-11-2010, 09:18 PM
sorry ... php 5.2 of course ... ;-)

angst
01-11-2010, 09:21 PM
what is the exact error message that your receiving ?

angst
01-11-2010, 09:26 PM
i'm running php 5.2.6 and I didn't get any errors while using your script.

zeroge
01-11-2010, 09:28 PM
its just a plain simple

"fatal error"

Nothing else. The error is shown on the page that should open (thank you page) and this is the page with the code on it.

Thanks

If you like, you can check it out - i send you the url, then

zeroge
01-11-2010, 09:30 PM
hello angst, well, that's strange twice ...

I didn't get any error before the upgrade but now and you DON't get an error? Now I'm really puzzled ... any ideas why I'd get any?

thanks

zeroge
01-11-2010, 09:31 PM
I run on 5.2.11

angst
01-11-2010, 09:32 PM
yah sure, send me the url. I'd like to see.

and no, I don't receive any errors, it just sends the emails.

zeroge
01-11-2010, 09:35 PM
http://chinabiz21.com/

just do the quick survey ... 10 sec, and choose to refer your friend (input some fake email, sure) and the you get the error (should get) ;-)

Thanks

angst
01-11-2010, 09:39 PM
well your not going to like this..lol..
but I didn't get an error on your site either:



Congratulations

That was easy!

... and see you soon at our winnerS party soon

Want to be a SUPER HERO? Spread the word and invite your friends and colleagues! to know, too!

They will sure appreciate you sharing this great opportunity with them. And who knows. What goes one way always need to go back!

zeroge
01-11-2010, 09:40 PM
http://www.chinabiz21.com/support/tellafriendchinabiz21.php

another link without the lightbox. It uses the same scrip and produces the same error, just realised it now.

If you don't get errors and I do ... what could be the reason for that? it's really strange.

zeroge
01-11-2010, 09:43 PM
THAT IS WEIRD WEIRD ... ???
Any idea WHY I should get the errors and you don't?

zeroge
01-11-2010, 09:45 PM
Ahh, IC
You didn't click on the link to fill in the referral form, did you? (last step)

angst
01-11-2010, 09:46 PM
ok, on the second one I do get an error.

it's coming from here:


mail($mailto, $subject, stripslashes($message), $header1) or exit('Fatal Mail Error!');
mail($Email, $ack_subject, $ack_message, $header2) or exit('Fatal Mail Error!');
mail($EMailList, $ack_subject2, $ack_message2, $header1) or exit('Fatal Mail Error!');


could you please change the code to this ( below ) and run it again, so we can see which instance of mail() is causing the issue?

ok, on the second one I do get an error.

it's coming from here:


mail($mailto, $subject, stripslashes($message), $header1) or exit('Fatal Mail Error! 1');
mail($Email, $ack_subject, $ack_message, $header2) or exit('Fatal Mail Error! 2');
mail($EMailList, $ack_subject2, $ack_message2, $header1) or exit('Fatal Mail Error! 3');


all I did was add numbers to the errors so we can see which one it's choking on.

zeroge
01-11-2010, 09:51 PM
I get... Fatal Mail Error! 2

angst
01-11-2010, 09:56 PM
ok, so for the second mail() function:


mail($Email, $ack_subject, $ack_message, $header2) or exit('Fatal Mail Error! 2');

we know for sure that you have the subject, message and $mailto, since those are all hard coded, but I don't see where $Email is coming from, so if that value is null/blank it's likely failing there.

try adding your email to that and see if the error still comes up.

$Email = "youremail@domain.com";
and move that to the top, or atleast before the mail() calls.

zeroge
01-11-2010, 09:59 PM
I just realised now... it doesn't actually send the invitations to the email addresses they were invited through the form.

It did it before though, with the older PHP version.

All it does no is send the one who invited others a thank you notice and to the administer a mail so we know who invited and who (should) have been invited (if they would have gotten the mail

zeroge
01-11-2010, 10:08 PM
since my email is defined in(under)

$mailto = "<mymail@mydomain.com>";

right at the top of the code, wouldn't there a conflict between the $mailto and $Email then? and I thought Email should be one of the referral email addresses ...

Do I have a mix here? and is this the reason for the error, now?

zeroge
01-11-2010, 10:11 PM
Though I tried to add this but then I get the error on line 3 now ... ;-)

angst
01-11-2010, 10:14 PM
ok, #3 is the same failure, on $EMailList, try the same thing and see if it goes away. it must be that in the older version of php mail would be sent regardless, but the new version is halting if these fields don't hold a value.

zeroge
01-11-2010, 10:17 PM
the form suppose to send invitation to email addresses of three fields. named;
EMailList
elista
elistb
the referrer' emial input field is named;
Email
... and he should get the thank you letter (he does)

I get all there referred email addresses sent to my mailto address but I see now I also get the invitation mail (instead the one who should get it?!

angst
01-11-2010, 10:20 PM
ok, then you see to get that data from the form and insert it into the code;



$Email = $_POST["Email"];

zeroge
01-11-2010, 10:25 PM
I added it and YEP, it certainly fixed the errors and I see the thank you page

B U T

While before the referre got the thank you mail ... I get all three mail

I get the notice who was referred by whom ... CORRECT
I get the thank you message (before it was sent to the referrer) AND
I get the invitation letter (I got before, too)

zeroge
01-11-2010, 10:29 PM
yep, that's what I thought I did ..

$name = Valid_Input($_POST['Email']);
$email = !empty($_POST['Email']) && valid_email($_POST['Email']) ? $_POST['Email'] : $mailto;
foreach ($_POST as $key => $value){
if (!is_array($value)){
$message .= "\n".$key." : ".$value;
}
else{
foreach ($_POST[$key] as $itemvalue){
$message .= "\n".$key." : ".$itemvalue;


But I see I only have EMAIL, which would explain that the referrer got the invitation letter before.

I guess I am missing something for the other three fields ... should I just add below
$name = Valid_Input($_POST['Email']);

$name = Valid_Input($_POST['EMailList']);
$name = Valid_Input($_POST['emaila']);
$name = Valid_Input($_POST['emailb']);

???

zeroge
01-12-2010, 01:02 AM
OK let's start from the very beginning, since my PHP 5.2 upgrade throws me too many errors.

My sendmail php goes like this

<?php

if ($_SERVER['REQUEST_METHOD'] != 'POST'){
header('Refresh: 0; URL=/index.php');
exit;
}

$mailto = "<me@myurl.com>";
$subject = "Expat Survey Result";
$message = "Values submitted from Expats Survey form:\n";
$message .= "IP address : ";
$message .= $_SERVER['REMOTE_ADDR'];
foreach ($_POST as $key => $value){
if (!is_array($value)){
$message .= "\n".$key." : ".$value;
}
else{
foreach ($_POST[$key] as $itemvalue){
$message .= "\n".$key." : ".$itemvalue;
}
}
}
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/plain; charset=utf-8\n";
$header .= "Content-Transfer-Encoding: 8bit\n";
$header .= "X-Mailer: PHP v".phpversion();

mail($mailto, $subject, stripslashes($message)) or exit('Fatal Mail Error!');

function Valid_Input($data){
list($data) = preg_split('/\r|\n|%0A|%0D|0x0A|0x0D/i',ltrim($data));
return $data;
}
?>

Cool, I get the mail from NOBODY. Sure, because no header defined.

Now I add some code to make it look like


<?php

if ($_SERVER['REQUEST_METHOD'] != 'POST'){
header('Refresh: 0; URL=/index.html');
exit;
}

$mailto = "<me@myurl.com>";
$subject = "Expat Survey Email";
$message = "Values submitted through the Expat Survey form:\n";
$name = Valid_Input($_POST['Email']);
$email = !empty($_POST['Email']) && valid_email($_POST['Email']) ? $_POST['Email'] : $mailto;
$message .= "IP address : ";
$message .= $_SERVER['REMOTE_ADDR'];
foreach ($_POST as $key => $value){
if (!is_array($value)){
$message .= "\n".$key." : ".$value;
}
else{
foreach ($_POST[$key] as $itemvalue){
$message .= "\n".$key." : ".$itemvalue;
}
}
}
$header1 = "From: ".$name." <".$Email.">\n";
$header1 .= "Reply-To: ".$Email."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/plain; charset=utf-8\n";
$header .= "Content-Transfer-Encoding: 8bit\n";
$header .= "X-Mailer: PHP v".phpversion();

mail($mailto, $subject, stripslashes($message), $header1) or exit('Fatal Mail Error!');

function Valid_Input($data){
list($data) = preg_split('/\r|\n|%0A|%0D|0x0A|0x0D/i',ltrim($data));
return $data;
}
?>

The lines I added are now line 11/12 , 25/26 and 32

Cool, I get the mail too but the "NOBODY" in FROM is gone and was replaced by a SYNTAX error ...?

Can someone help please?

That would help me to solve my much bigger problem when I come back to sending email to referrals

THANKS A 8b TIMES



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum