简体   繁体   中英

PHP Pear Mail not sending email with special characters

I have the following problem. I have an online application form in HTML posting to a php file. The php file should send the contents via email. It works perfectly except when the client's name posting has special characters such as ü etc. It does not give any errors on form submission it just does not send the email.

This is my code:

  $host = "192.168.10.14";
$username = "exxxx@xxx.com";
$password = "xxxxx";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = new Mail_mime(array("text_charset" => "utf-8",
                            "html_charset" => "utf-8",
                            "eol" => "\n"));
    foreach ($headers as $name => $value){
    $headers[$name] = $mail->encodeHeader($name, $value, "utf-8",
                                                           "quoted-printable");
    }
// also encode to value
$to = $mail->encodeHeader("to", $to, "utf-8", "quoted-printable");
// fetch message
$msgDone = $mail->get();
// let Mail_Mime finish the headers (adds e.g. MIME info)
$headers_done = $mail->headers($headers);
// send the email

$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);


if (PEAR::isError($mail2)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {



header("Refresh: 0;url=OK.html");

  }

It works perfectly unless there are special characters. When there are special characters it does not send the email at all without any warnings.

Thanks

Have you tried cleaning your input before allowing it to be sent?

Would you allow an apostrophe to be entered in to an SQL statement without escaping it? Also check your mail logs on the server - that should provide a better hint to the underlying issue.

Thanks, //P

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