2013-05-30 25 views
0

我已经在PHP /电子邮件“地狱” - 我接近,似乎并不能去的“终点线” ....PHPMailer的,电子邮件的行为神秘

嗡使用的PHPMailer发送支持在客户端的请求。我的过程如下所示: FORM - > PROCESS(生成反馈消息和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('[email protected]', 'no-reply @ this domain'); 

//Set an alternative reply-to address 
//$mail->AddReplyTo('[email protected]','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; 
} 
?> 

帮助 - 请

回答

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文件打开,在这种情况下,你赢了” t需要ob_start()和ob_end_flush()语句。我的php.ini文件有这样的:

output_buffering = 4096 
+0

有没有办法在PHP中抑制输出? – jpmyob

+0

是的,我编辑了我的答案,在php中包含有关输出缓冲的一些信息。 – vjones