如何使用PHP发送欢迎电子邮件和重定向页面

时间:2012-09-17 17:00:38

标签: php email

目前我有下面的代码,它将html输入字段(email)的内容发送到welcome@domain.com地址。我现在正在努力解决两件事。我使用了以下几段代码无济于事 -

$to = "welcome@domain.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";

mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thankyou.html');
  1. 如何从welcome@domain.com自动发送电子邮件回复?

  2. 而不是页面上写着“感谢您与我们联系,我们会很快联系”有没有办法将它们重定向到domain.com/thankyou.html?

  3. 这是代码的其余部分似乎工作正常!如果对此有任何建议,虽然它们总是非常受欢迎!

    if(isset($_POST['email'])) {
    
    $email_to = "welcome@domain.com";
    $email_subject = "Your spot has been saved!";
    function died($error) {
    
    
    echo "We are very sorry, but there were error(s) found with the form your submitted";
    echo "These errors appear below<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors<br /><br />";
    die();
    }
    
    
    if(
    !isset($_POST['email'])
    ) {
    died("We are sorry, but there appears to be a problem with the form your submitted!");
    }
    $email_from = $_POST['email']; 
    $error_message = "";
    $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
    if(!eregi($email_exp,$email_from)) {
    $error_message .= "The Email Address you entered does not appear to be valid!<br />";
    }
    if(strlen($error_message) > 0) {
    died($error_message);
    }
    $email_message = "Form details below.\n\n";
    function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }
    $email_message .= 'Email: '.clean_string($email_from)."\n";
    
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>
    Thank you for contacting us. We will be in touch with you very soon.
    <?
    }
    ?>
    

1 个答案:

答案 0 :(得分:0)

关于未重定向的页面,请参阅此帖子stackoverflow.com/questions/6396813/php-header-not-redirecting 它基本上表示在标题调用之前不得输出任何值。

对于邮件问题,请详细说明您遇到的错误。