0

我一直在 PHP/电子邮件“地狱” - 我接近了,似乎无法到达“终点线”....

Om 使用 phpmailer 在客户站点中发送支持请求。我的流程如下所示:表单 -> 流程(生成反馈消息和 cc 消息以支持)-> 邮件发送给发件人 -> 邮件支持 -> 重定向到感谢页面。

问题有两个方面:1)如果我打开了调试,电子邮件会按预期通过,但我得到了调试并且没有重定向 2)如果我关闭调试 - 电子邮件不会发出并且我得到一个空白页 -没有重定向

* 附录 * 电子邮件刚刚通过 - 所以这只是一个重定向问题......无论有没有调试,我的元刷新都不会发送 - 也许有更好的方法????

PHP 表单处理器

...
// send two emails
    $_emailTo = $email; // the email of the person requesting
    $_emailBody = $text_body; // the stock response with things filled in
    include ( 'email.php' );

    $_emailTo = $notifyEmail; // the support email address
    $_emailBody = $pretext.$text_body; // pretext added as meta data for support w/ same txt sent to user
    include ( 'email.php' );

// relocate
    echo '<META HTTP-EQUIV="Refresh" Content="0; URL=success.php" >';
    exit;

PHP 邮件程序 (email.php)

<?php
    require 'phpmailer/class.phpmailer.php';

//Create a new PHPMailer instance
$mail = new PHPMailer();

//Tell PHPMailer to use SMTP
$mail->IsSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;

//Set the hostname of the mail server
$mail->Host = "mail.validmailserver.com";

//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 26;

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication
$mail->Username = "validusername";

//Password to use for SMTP authentication
$mail->Password = "pass1234";

//Set who the message is to be sent from
$mail->SetFrom('me@validmailserver.com', 'no-reply @ this domain');

//Set an alternative reply-to address
//$mail->AddReplyTo('no-reply@validmailserver.com','Support');

//Set who the message is to be sent to
$mail->AddAddress( $_emailTo );
$mail->Subject = $_emailSubject;
$mail->MsgHTML( $_emailBody );

$_emailError = false;

//Send the message, check for errors
if( !$mail -> Send() ) {
    $_emailError = true;
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
?>

请帮忙

4

1 回答 1

1

您的问题可能是在尝试重定向之前已经将一些输出发送到浏览器。在这种情况下,您通常无法进行重定向。如果是这种情况,您可以使用输出缓冲,如下例所示:

ob_start();
//statements that output data to the browser
print "some text";
if (!headers_sent()) {
    header('Location: /success.php');
    exit; 
}
ob_end_flush();

这也可以在 php.ini 文件中使用输出缓冲指令默认打开,在这种情况下,您不需要 ob_start() 和 ob_end_flush() 语句。我的 php.ini 文件有这个:

output_buffering = 4096
于 2013-05-30T05:05:33.130 回答