因此,我有一个脚本,可以从网页上的表单发送邮件。用户只需输入他的邮件地址,消息和他的名字。
首先,我将邮件发送到我的联系地址。(这工作正常)之后,我将邮件发送到用户的邮件地址。(这不起作用)
最后一个邮件功能返回成功,但用户没有邮件。
我尝试记录所有内容,但无法弄清楚为什么可能发送了邮件却没有收到邮件。
当我体内带有“ repondons”之类的法国口音时,邮件不会发送,但当它只是“ repondons”时,邮件仍然有效。我不明白为什么,但是带重音会更好
<?php
// site owner
$site_name = 'just-request.fr';
$sender_domain = '[email protected]';
$to = '[email protected]';
// contact form fields
$name = trim( $_POST['name'] );
$email = trim( $_POST['email'] );
$subject = trim( $_POST['subject'] );
$message = trim( $_POST['message'] );
// check for error
$error = false;
if ( $name === "" ) { $error = true; }
if ( $email === "" ) { $error = true; }
if ( $subject === "" ) { $error = true; }
if ( $message === "" ) { $error = true; }
// if no error, then send mail
if ( $error == false )
{
$body = "Name: $name \n\nEmail: $email \n\nMessage: $message";
$headers = "From: " . $site_name . ' <' . $sender_domain . '> ' . "\r\n";
$headers .= "Reply-To: " . $name . ' <' . $email . '> ' . "\r\n";
$mail_result = mail( $to, utf8_decode($subject), utf8_decode($body), $headers );
if ( $mail_result == true )
{
$body = "Bonjour,\n\n";
$body .= "Merci de votre mail, nous le prenons en compte et vous repondrons des que possible.\n\n";
$body .= "Cordialement,\n";
$body .= "L'equipe Request. ";
$subject = "Réponse automatique";
$new_mail_result = mail( $email, utf8_decode($subject), utf8_decode($body), $headers );
if ( $new_mail_result == true )
{
echo 'success';
}
else
{
echo 'unsuccess';
}
}
else
{
echo 'unsuccess';
}
}
else
{
echo 'error';
}
尝试使用mb_send_mail()代替mail()。
将mb_language()设置为German/de
(ISO-8859-15)或English/en
(ISO-8859-1)。
无论ISO-8859-15和ISO-8859-1包括法国多余的字母。欧元升级后,
ISO-8859-15为ISO-8859-1。
https://www.php.net/manual/zh/function.mb-send-mail.php
发送电子邮件。标头和消息根据mb_language()设置进行转换和编码。这是mail()的包装函数,因此,有关详细信息,另请参见mail()。
评论:我错过了带引号可打印编码的UTF-8的mb_language()选项。对于大多数(欧洲)“几乎ASCII ”语言特定的字母来说,这将是很好的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句