我一直在PHP /电子邮件'地狱' - 我接近了,似乎无法进入'终点线'....
使用phpmailer在客户端站点中发送支持请求。我的过程看起来像这样: 表格 - > PROCESS(生成反馈消息和cc消息以支持) - >邮寄给发件人 - >邮件支持 - >重定向到感谢页面。
问题有两个: 1)如果我打开了debuging,电子邮件会按预期通过,但我得到调试并且没有重定向 2)如果我关闭调试 - 电子邮件不会出去我得到一个空白页 - 没有重定向
*附录* 电子邮件刚刚通过 - 所以它只是一个重定向问题...无论有没有调试,我的元刷新都没有发送 - 也许有更好的方法????
PHP FORM PROCESSOR
...
// 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 MAILER(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;
}
?>
帮助 - 请
答案 0 :(得分:1)
您的问题可能是在尝试重定向之前,某些输出已经发送到浏览器。在这种情况下,您通常无法进行重定向。如果是这种情况,您可以使用输出缓冲,如下例所示:
ob_start();
//statements that output data to the browser
print "some text";
if (!headers_sent()) {
header('Location: /success.php');
exit;
}
ob_end_flush();
默认情况下,这也可以在带有output buffering指令的php.ini文件中打开,在这种情况下,您不需要ob_start()和ob_end_flush()语句。我的php.ini文件包含:
output_buffering = 4096