【问题标题】:phpmailer, email behavior mysteryphpmailer,电子邮件行为之谜
【发布时间】:2013-05-30 04:09:18
【问题描述】:

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

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

问题有两个方面: 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;
} 
?>

请帮忙

【问题讨论】:

    标签: php phpmailer


    【解决方案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 文件中使用 output buffering 指令默认打开,在这种情况下,您不需要 ob_start() 和 ob_end_flush() 语句。我的 php.ini 文件有这个:

    output_buffering = 4096
    

    【讨论】:

    • php 中有没有办法抑制输出?
    • 是的,我已经编辑了我的答案以包含一些关于 php 中的输出缓冲的信息。
    猜你喜欢
    • 2011-07-21
    • 2019-01-03
    • 2015-04-13
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    相关资源
    最近更新 更多