【问题标题】:Unable to send an email using php on windows 8 [duplicate]无法在 Windows 8 上使用 php 发送电子邮件 [重复]
【发布时间】:2014-09-05 00:09:25
【问题描述】:

我一直在尝试使用 php 发送电子邮件,当我尝试在 Linux 上运行代码但无法在 Windows 8 上运行它时,我能够发送电子邮件,我在 Windows 上安装了 XAMPP。这是代码。

<?php
 $msg = "Checking Email";
 $msg = wordwrap($msg,70);
 mail("myemailaddress","My subject",$msg);
?>

我上网查了一下,发现我要编辑php.ini 和sendmail.ini 文件。我不确定这是正确的解决方案。如果是,任何人都可以告诉我我究竟需要编辑或更改什么,因为我试图编辑这些文件但它仍然无法正常工作。

谢谢

【问题讨论】:

    标签: php html linux windows xampp


    【解决方案1】:

    如果我是你,我会尝试使用 PHPMailer。我更喜欢使用它而不是系统内置的 PHP。我觉得不那么麻烦。 以下是您可以使用它执行的一些操作:

    <?php
    require 'PHPMailerAutoload.php';
    
    $mail = new PHPMailer;
    
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'user@example.com';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
    
    $mail->From = 'from@example.com';
    $mail->FromName = 'Mailer';
    $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');
    
    $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
    $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';
    
    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
    

    有更多关于他们的github page 的信息。如果您可以使用电子邮件凭据访问网络服务器,那么设置它应该没有问题 - 您需要一个主机,而不仅仅是 XAMPP 或 LAMP(假设您最终打算获得它)。

    【讨论】:

      猜你喜欢
      • 2015-08-17
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 2013-07-15
      • 1970-01-01
      相关资源
      最近更新 更多