PHPMailer不能使用XAMPP。没有错误。没有电子邮件。不工作? [英] PHPMailer will not work with XAMPP. No Errors. No Emails. Not working?

查看:146
本文介绍了PHPMailer不能使用XAMPP。没有错误。没有电子邮件。不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的测试网站上使用XAMPP和PHPMailer作为简单的CONTACT ME电子邮件表单。问题如下。我似乎无法发送测试电子邮件来确定它是否正常工作。我花了大部分时间试图找出这个问题的根源,但我仍然无法找到答案。它甚至不告诉我是否出现问题。

我根据web / StackOverFlow / Documentation试过了以下内容:




  • 从php.ini中为行extension = php_openssl.dll删除分号
  • 重新启动XAMMP
  • 更新端口和主机值*

  • 来自https://github.com/PHPMailer/PHPMailer的DLd PHPMailer

  • 观看了PHPAcademy的建立一个PHP联系表格Youtube上的视频
  • 其实95%的代码是他的......对我来说不起作用 li>
  • 在他的视频中留下评论。



我已浏览了本网站上的大部分问题,并未提出任何可以解决问题的方法问题。我正在阅读安静的一些文档,到目前为止。我似乎在做正确的事情。因此,这让我感到困惑,这种简单的形式并不适合我。

contact.php

 <?php 
在session_start();
require_once'helpers / security.php';
$ errors = isset($ _ SESSION ['errors'])? $ _SESSION ['errors']:[];
$ fields = isset($ _ SESSION ['fields'])? $ _SESSION ['fields']:[];

?>

<!DOCTYPE html>
< html lang =eng>
< head>
< meta charset =UTF-8>
< title>联络表格< / title>
< link rel =stylesheethref =indexContactStyle.css>

< / head>
< body>
< div class =contact>
<?php if(!empty($ errors)):?>
< div class =panel>
< ul> <李> <?php echo implode('< / li>< li>',$ errors); ?> < /锂> < / UL>
< / div>
<?php endif?>

< form action =contact.phpmethod =post>
< label>
您的姓名*< input type =textname =inputNameautocomplete =off<?php echo isset($ fields ['name'])? 'value =''。e($ fields ['name'])。'':''?> >
< / label>
< label>
您的电子邮件*< input type =textname =inputEmailautocomplete =off<?php echo isset($ fields ['email'])? 'value =''。e($ fields ['email'])。''':''?> >
< / label>
< label>
Your Message *< textarea name =messagerows =8><?php echo isset($ fields ['message'])? e($ fields ['message']):''?>< / textarea>
< / label>
< input type =submitvalue =发送>
< p class =muted> *表示必填字段< / p>
< button class =mutedtype =buttononClick =goBack()>返回< / button>
< / form>
< / div>
< / body>
< / html>

<?php
unset($ _ SESSION ['errors']);
unset($ _ SESSION ['fields']);
?>

index.php

 <?php 

session_start();

require_once'libs / phpMailer / PHPMailerAutoload.php';


$ errors = [];

print_r($ _ POST);
if(isset($ _ POST ['inputName'],$ _POST ['inputEmail'],$ _POST ['message'])){


$ fields = [
'name'=> htmlentities($ _POST ['inputName']),
'email'=> $ _POST ['inputEmail'],
'message'=> $ _POST ['message']

];



foreach($ fields as $ field => $ data){

if(empty($ data)){
$ errors [] ='The'。 $字段。 '必填字段';



$ b if(empty($ errors)){
$ m = new PHPMailer;

$ m-> isSMTP();
$ m-> SMTPauth = true;
$ m-> SMTDebug = true;
$ m-> Host ='smtp.gmail.com';
$ m->使用者名称='myEmail@gmail.com';
$ m->密码='myPass';
$ m-> SMTPSecure ='ssl';
$ m->端口= 465;

$ m-> isHTML(true);

$ m->主题='联系表单提交';

$ m-> Body ='From:'。$ fields ['name']。 '('。$ fields ['email']。')< p> '。 $ fields ['message']。 '< / p> ';

$ m-> FromName ='联络';
//不完全确定应该在这里发生什么。一些人将自己的电子邮件发送给其他人发送人的电子邮件。哪一个?
$ m-> AddAddress('myEmail@gmail.com','myName');
$ b $ if($ m-> send()){
header('Location:thanks.php');
die();
} else {
$ errors [] ='抱歉无法发送电子邮件。稍后再试 ';
}

}


}其他{
$ errors [] ='有些事情可能是错误的!
}


$ _SESSION ['errors'] = $ errors;

$ _SESSION ['fields'] = $ fields;

header('Location:contact.php');


解决方案

您可以尝试几件事:




  • PHP属性和变量区分大小写,所以 SMTPauth 应该
    SMTPAuth

  • SMTPDebug 需要一个整数,而不是布尔值,所以将它设置为1或更高的调试输出,0关闭它。

  • 对于gmail,将 SMTPSecure 设置为'tls', Port 为587。
  • AddAdress 用于添加普通的'收件人'你可以为每个你想要消息的人打电话(可以有多个)。

  • 不要调用 die()发送成功后 - 你的脚本将正常终止,没有这个。 - 如果你正在生成任何调试输出,重定向到你的感谢页面将不起作用(你会得到一个'headers already sent'错误),所以你正在调试的时候可能只想在这里回应一些东西,所以你知道这是行得通的。



大部分代码看起来像编写该课程的人正在使用旧版本的PHPMailer。


I'm currently using XAMPP and PHPMailer for a simple 'CONTACT ME' email form on my test-website. The problem is as follows. I cannot seem to be able to send out a test email to make sure if it is working. I've spent the majority of my weekend trying to find out the root of this problem but I still cannot seem to find an answer. It does not even tell me if something went wrong or not.

I've tried the following according to the web/ StackOverFlow/ Documentation:

  • removed semicolon from php.ini for line "extension=php_openssl.dll"
  • restarted XAMMP
  • updated port and host values *seen below*
  • DLd PHPMailer from https://github.com/PHPMailer/PHPMailer
  • watched PHPAcademy's "Build A PHP Contact Form" Video on Youtube
  • Actually 95% of his code is his...just doesn't work for me
  • Left a comment on his video. No response as of yet.

I've looked through most of the questions on this site and came up with nothing that can resolve my problem. I'm reading through quiet a few of documentation and so far. I seem to be doing the right thing. Therefore it baffles me that this simple form is not working for me.

contact.php

<?php
  session_start();
  require_once 'helpers/security.php';
  $errors = isset($_SESSION['errors']) ? $_SESSION['errors'] : [];
  $fields = isset($_SESSION['fields']) ? $_SESSION['fields'] : [];

?>

<!DOCTYPE html>
<html lang="eng">
  <head>
    <meta charset="UTF-8">
    <title>Contact Form</title>
    <link rel="stylesheet" href="indexContactStyle.css">

  </head>
<body>
  <div class="contact">
  <?php if( !empty($errors)) :  ?>
    <div class="panel">  
      <ul>  <li>  <?php echo implode('</li><li>', $errors ); ?>  </li>  </ul>
    </div>
  <?php endif ?>

  <form action="contact.php" method="post">
    <label>
      Your Name * <input type="text" name="inputName" autocomplete="off" <?php echo isset($fields['name']) ? ' value= " '. e($fields['name']) .' " ' : '' ?> >
    </label>
    <label>
      Your Email * <input type="text" name="inputEmail" autocomplete="off" <?php echo isset($fields['email']) ? ' value= " '. e($fields['email']) .' " ' : '' ?> >
    </label> 
    <label>
      Your Message * <textarea name="message" rows="8"><?php echo isset($fields['message']) ? e($fields['message']) : '' ?></textarea>
    </label>       
    <input type="submit" value="Send">
    <p class="muted"> * means a required field</p>
    <button class="muted" type="button" onClick="goBack()">Back</button>
      </form>
    </div>
  </body>
</html>

<?php
  unset($_SESSION['errors']);
  unset($_SESSION['fields']);
?>

index.php

<?php

session_start();

require_once 'libs/phpMailer/PHPMailerAutoload.php';


$errors = []; 

print_r($_POST);
if (isset($_POST['inputName'], $_POST['inputEmail'], $_POST['message'])) {


$fields = [
    'name' => htmlentities( $_POST['inputName'] ),
    'email' => $_POST['inputEmail'],
    'message'=> $_POST['message']

];



foreach ($fields as $field => $data) {

    if( empty($data) ) {
        $errors[] = 'The ' . $field . 'field is required.';
    }

} 

if(empty($errors)) {
    $m = new PHPMailer;

    $m->isSMTP();
    $m->SMTPauth = true;
    $m->SMTDebug = true;
    $m->Host ='smtp.gmail.com';
    $m->Username = 'myEmail@gmail.com';
    $m->Password = 'myPass';
    $m->SMTPSecure = 'ssl';
    $m->Port = 465;

    $m->isHTML(true);

    $m->Subject = 'Contact form submitted';

    $m->Body ='From: ' .$fields['name'] .  ' ( ' . $fields['email'] . ' ) <p> ' .  $fields['message'] . ' </p> ' ;

    $m->FromName = 'Contact';
    // Not entirely sure what is supposed to go here. Some ppl put their own email others the email of the sender. which one is it?
    $m->AddAddress('myEmail@gmail.com', 'myName');

    if ( $m->send() ) {
        header('Location: thanks.php');
        die();
    } else {
        $errors[] = 'Sorry could not send email. Try again later ';
    }

}


} else {
$errors[] = 'Something went HORRIBLY WRONG!!';
}


$_SESSION['errors'] = $errors;

$_SESSION['fields'] = $fields;

header('Location: contact.php');

解决方案

A few things you can try:

  • PHP properties and variables are case-sensitive, so SMTPauth should be SMTPAuth.
  • SMTPDebug takes an integer, not a boolean, so set it to 1 or above for debug output, 0 to turn it off.
  • For gmail, set SMTPSecure to 'tls', and Port to 587.
  • AddAdress is used to add normal 'To' recipients - you call this for each person you want the message to go to (there can be more than one).
  • Don't call die() after successful sending - your script will terminate normally without that. - If you are generating any debug output, the redirect to your 'thanks' page will not work (you'll get a 'headers already sent' error), so whil you are debugging you might want to just echo something here instead so you know it's worked.

Much of the code looks like whoever wrote the course was working with an old version of PHPMailer.

这篇关于PHPMailer不能使用XAMPP。没有错误。没有电子邮件。不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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