phpmailer不会在提交表格后发送电子邮件 [英] phpmailer wont send email after submitting form

查看:100
本文介绍了phpmailer不会在提交表格后发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我搞砸了phpmailer,我已经一切正常.
但是我现在想做的是提交表单后发送邮件. 只需提交一封确认表单的基本电子邮件(没有表单数据),就没什么困难了.



Im messing around with phpmailer and i've got everything working.
But what im trying to do now is after submitting a form send a mail. Not anything too difficult just a basic email that acknowledges the form has been submitted (no form data).

问题:提交表单后,电子邮件未发送(电子邮件代码已通过100%测试)

problem : email is not sending after submitting form (email code is working 100% tested)

希望有人可以帮助我:)

mail.php代码:

Hope someone can help me out :)

mail.php code :

<?php
//ini_set(‘display_errors’, 1);

include '/var/www/includes/mailer.php';

//require 'PHPMailerAutoload.php';

 $mail = new PHPMailer;

 $mail->SMTPDebug = 3;                                 // Enable verbose      debug output

$mail->isSMTP();                                      // Set mailer to  use SMTP
$mail->Host = 'smtp.nicetrygoyim.nl';                       //Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication


$mail->Username = 'secret@secret.com';          // SMTP username
$mail->Password = 'nicetry';                             // SMTP password
$mail->SMTPSecure = 'TLS';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('secret@secret.com', 'Mailer');
$mail->addAddress('secret@secret.com', 'secret');     // Add a recipient
$mail->addAddress('secret@secret.com', 'secret');               // Name is optional
//$mail->addReplyTo('secret@secret.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
 $mail->isHTML(true);                                  // Set email format to HTML

  $mail->Subject = 'Here is the subject';
  $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
  $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';


   $mail->smtpConnect([
   'ssl' => [
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
     ]
      ]);

     if(!$mail->send()) {
     echo 'Message could not be sent.';
     echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
    echo 'Message has been sent';
    }
    ?> 

我的表格:

<form action="mail.php" method="post">
 Leerlingnummer:<br>
 <input type="text" name="leerlingnummer"required placeholder="Voer hier het leerlingnummer in" /><br>
 E-mailadres:<br>

 <input type="submit" name="submit" class="groottext" value="Reparatie    indienen"/>

错字

忘记提及问题

edit : typo

edit : forgot to mention problem

推荐答案

如果此代码正在运行,则即使调试正常,您也应该会看到大量调试输出.您实际上并没有说出问题所在,但是您所做的一些错误是我可以看到的.如果您将代码基于所提供的示例,并阅读文档,那将真的有帮助只是猜测.

If this code is running, you should be seeing a ton of debug output, even if it is working correctly. You don't actually say what the problem is, but you're doing a few things wrong that I can see. It would really help if you based your code on the examples provided and read the docs instead of just guessing.

$mail->SMTPSecure = 'TLS';

应为:

$mail->SMTPSecure = 'tls';

不要自己打smtpConnect(),您会弄乱SMTP事务状态的跟踪.如果要设置SSL参数,请按预期方式设置它们,然后只需调用send()即可处理连接:

Don't call smtpConnect() yourself, you'll mess up the tracking of SMTP transaction state. If you want to set SSL params, set them the expected way and then just call send(), which will deal with the connection:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

下一个问题是您为什么要这样做?如果您不能提供明确的特定原因,那么您在做错什么了.

The next question is why are you doing that? If you can't provide an explicit, specific reason for doing that, you're doing something wrong.

这篇关于phpmailer不会在提交表格后发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆