TEL:400-8793-956
当前位置:程序、服务器

PHP邮件功能if语句

提问者: 近期获赞: 浏览人数: 发布时间:2021-01-14 13:23:46

 问:我想在下面的带有失败消息的邮件功能中使用另一个if语句。

 
因此,当不发送邮件时,它可以在屏幕上显示失败消息
 
<?php 
if(isset($_POST['submit'])){
    $to = "Test@gmail.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_na = $_POST['first_name'];
    $last_nae = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    
mail($to,$subject,$message,$headers);
    
    
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    // You cannot use header and echo together. It's one or the other.
}
?>
 
答:如果要在失败时显示消息,则需要使用如下所示的邮件功能。if(mail($ to,$ subject,$ message,$ headers)){回显'已发送邮件'; } else {echo'邮件未发送'; }
上一篇: 在GeckoFX Web浏览器中管理新窗口
下一篇: 项目管理软件中最显着的功能是什么?