dongqiaozhe5070 2014-10-06 16:43
浏览 31
已采纳

PHP邮件程序编码问题

I am having an issue with getting my PHP mailer code to work correctly. I can get it to send an email on page load fine, the issue is with the ISSET command to get it to submit the form once the submit button has been pressed. I have tried putting it in various places but still can't get it to work. Any help would be appreciated.

<?php
require '/phpmailer/PHPMailerAutoload.php';
require_once '/phpmailer/class.phpmailer.php';
include '/phpmailer/class.smtp.php';

if(isset($_POST["Submit"])) 
{

$emailaddress = '****@**********';

$message=
    'Name:  '.$_POST['name'].'<br />
    Email:  '.$_POST['email'].'<br />
    IP: '.$_SERVER['REMOTE_ADDR'].'<br /><br />
    Message:<br /><br />
    '.nl2br($_POST['message']).'
    ';

$mail             = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "********"; // SMTP server
$mail->SMTPDebug  = 1;                     // 1 = errors and messages,2 = messages only
$mail->SMTPAuth   = false;                  // enable SMTP authentication
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->SMTPSecure = 'false';                            // Enable encryption, 'ssl' also accepted
$mail->CharSet  = 'UTF-8';  // so it interprets foreign characters
$mail->setFrom('***********');
$mail->AddReplyTo('**********');
$mail->Subject    = "Contact form submission from ".$_POST['name']." ";
$mail->MsgHTML($message);
$mail->AddAddress($emailaddress);

if(!$mail->Send())
{
    echo "Message could not be sent. <p>";
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
}

    echo "Thank you, your message has been sent!";
}
  • 写回答

1条回答 默认 最新

  • douyu0792 2014-10-06 16:47
    关注

    I'm going to make my comment as an answer, because that is the only conclusion I can come up with and the most likely to be, without seeing the OP's HTML form.

    Your conditional statement if(isset($_POST["Submit"])) is based on a submit button named Submit. If your submit button has name="submit" instead of name="Submit", then that would explain it. If it isn't named, then do.

    I.e.:

    <input type="submit" name="Submit" value="Send Email">
    

    is not the same as

    <input type="submit" name="submit" value="Send Email">
    
    • POST variables are case-sensitive.

    Your presently shown code has the proper bracing.

    Having used error reporting and placed the top of your file(s) right after your opening <?php tag

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    

    would have signaled an Undefined index Submit... warning message.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测