简体   繁体   English

填写php表单发生错误时,我正尝试向自己发送电子邮件

[英]I am trying to send an email to myself when an error happens from filling out the php form

I am trying to send an email to myself when an error happens from filling out the php form instead of doing Print="Sorry an error happened" 我尝试通过填写php表单发生错误时向自己发送电子邮件,而不是执行Print =“抱歉,发生错误”

$error = "ERROR HAPPENED".$order."\r\n";
$error_email = mail($to, $subject, $error, $headers2);
$mail = @mail($email, $subject, $confirmation, $headers2);

if ($mail) {
    header("Location: http://www.test.com" );
} else ($error_email);

You're not using brackets after the else. 您没有在else之后使用方括号。

if($mail)
{
    header("Location: http://www.test.com");
}
else
{
    mail($to, $subject, $error, $headers2);
    echo $error;
}

And you were never using echo $error so the error couldn't be printed. 而且您从未使用过echo $ error,因此无法打印错误。

Your code is a little unclear - and it helps if you ask a question... 您的代码有点不清楚-如果您提出问题,它会有所帮助...

However, I'd suggest using a logging framework for this, such as log4php ; 但是,我建议为此使用日志记录框架,例如log4php this includes an email option, so errors can get mailed to you, or you can write them to disk, or the OS log file. 其中包括一个电子邮件选项,因此错误可以通过电子邮件发送给您,或者您可以将其写入磁盘或操作系统日志文件中。

Please be aware that email is totally insecure - it's easy to intercept them, and they are not encrypted. 请注意,电子邮件是完全不安全的-容易拦截它们,并且未加密。 I hope you're not sending sensitive data in the $order variable. 希望您不要在$ order变量中发送敏感数据。

Finally, your code is probably not doing what you want it to. 最后,您的代码可能没有按照您想要的去做。

$error = "ERROR HAPPENED".$order."\r\n";

Build the error string (assuming $order is nicely printable). 构建错误字符串(假设$ order可以很好地打印)。

$error_email = mail($to, $subject, $error, $headers2);

Send an email to $to. 发送电子邮件至$ to。 $error_email is now a boolean value. $ error_email现在是布尔值。

$mail = @mail($email, $subject, $confirmation, $headers2);

Send an email to $email. 发送电子邮件至$ email。 Suppress errors. 抑制错误。 $mail is a boolean. $ mail是一个布尔值。

if ($mail) {
    header("Location: http://www.test.com" );

if the mail was sent successfully (to $email), redirect the user. 如果邮件发送成功(发送到$ email),请重定向用户。

} else ($error_email);

If the mail was not sent successfully, not sure what you're trying to do... 如果邮件发送失败,则不确定您要执行的操作...

It's not a good idea to tie your application logic to the random "did I manage to send an email" success. 将您的应用程序逻辑与随机的“我设法发送电子邮件”成功绑定不是一个好主意。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使用PHP从FORM发送电子邮件,但是我收到的详细信息没有发件人电子邮件地址 - I am trying to send email from a FORM using PHP, but i receive the details without the From email Address 我正在尝试通过 php 从我的联系我们页面向 email 发送 email 但它给出了错误我的代码和错误如下 - i am trying to send an email from my contact us page to email by php but it gives error my code and error given below 我正在尝试使用codeigniter从cPanel发送电子邮件,但每次收到错误消息时都说连接超时 - I am trying to send email from cPanel using codeigniter but every time I get the error saying connection time out 尝试在PHP中更新表单时出现SQL错误 - I am getting a SQL error when trying to update a form in PHP 我测试用的简单表格的PHP / MySQL错误(我正在尝试向自己介绍一些MySQL / PHP) - PHP/MySQL error for a simple form i made for testing (i'm trying to teach myself some MySQL/PHP) 为什么我在尝试使用phpmailer发送电子邮件激活新用户帐户时收到此错误 - Why am i getting this error when trying to send email for activation of new user account with phpmailer 我在尝试发送电子邮件验证时遇到错误 - I am getting error while trying to send email verification 尝试从 HTML 表单发送带有 PHP 的 email 导致 Z293C9EA246FF9985DC6F62A4050F986Z 错误 - Trying to send an email with PHP from HTML form resulting in an HTTP Error 405 尝试将表单中的复选框值发送到PHP中的电子邮件 - Trying to send checkbox value(s) from form to email in PHP 尝试以表格形式发送电子邮件时收到405错误 - Getting 405 error when trying to send email in form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM