简体   繁体   中英

E-mail parsing addresses with junk characters

I'm sending e-mails through a form I coded and for some reason, for some cases the e-mail address becomes junk, and for other times it works fine.

//on form page
$message = str_replace("@e",$emtemail,$message);

$message is stored in SQL (defined on another page), same for $emtemail. $message is just the body of the e-mail being sent, and I'm replacing all instances of @e with the e-mail people send payments to. It sends one e-mail to the customer, and one e-mail to me.

//customer e-mail
//the display address might appear as payment52.62gmail.com instead of payment@gmail.com
//my e-mail
//all e-mail addresses formatted properly without error, @ appears as @

Why do e-mail addresses parse strangely? Something to do with encoding?

This is all of the code relevant to sending e-mails I have. I can't pinpoint the problem.

//any variables used in the below but not declared are previously initialized
$em = $userc["email"];
$subject = $emailone["subject"];
$subject = str_replace("@o",$ordernum,$subject);
$subject = str_replace("@u",htmlspecialchars($rn),$subject);
$subject = str_replace("@g",$gt,$subject);
$subject = str_replace("@sl","www.SZVapor.com",$subject);
$subject = str_replace("@ss","SZVapor.com",$subject);
$subject = str_replace("@st","SZVapor",$subject);
$message = nl2br($emailone["message"]);
$message = str_replace("@o",$ordernum,$message);
$message = str_replace("@u",htmlspecialchars($rn),$message);
$message = str_replace("@t",$table,$message);
$message = str_replace("@e",$emtemail,$message);
$message = str_replace("@g",$gt,$message);
$message = str_replace("@a",$addrsubmit,$message);
$message = str_replace("@sl","www.SZVapor.com",$message);
$message = str_replace("@ss","SZVapor.com",$message);
$message = str_replace("@st","SZVapor",$message);
$message = str_replace("@c",$em,$message);
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1"."\r\n";
$headers .= "From: no-reply@SZVapor.com";
mail($em, $subject, $message, $headers);

Some examples of e-mail addresses given:

payment62.44gmail.com
payment54.45gmail.com
payment22.59gmail.com
payment25.49gmail.com

http://php.net/manual/en/function.mail.php

The first parameter entry for mail is the email address.

The code above does not do anything with $em

And by the way, I think that the last header line should look like this:

$headers .= "From: no-reply@SZVapor.com" . "\r\n";

I solved the issue, and it was an error on my part. I was replacing all instances of certain character combinations with variables.

@g = replaced with grand total
@e = replaced with payment e-mail
@o = replaced with order number
etc

The order I did them in was such that I replaced @e with the e-mail payment@gmail.com, and then replaced all @g with the grand total, so payment* @g *mail.com became "payment".$grandtotal."mail.com" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM