【问题标题】:Mail is not send in wamp [duplicate]邮件未在 wamp 中发送 [重复]
【发布时间】:2013-10-11 06:34:29
【问题描述】:

我想使用mail函数从我的php脚本发送邮件。所以我安装了Wamp

并使用此link 设置sendmail.iniphp.ini

当我运行我的 php 程序时,它会给出:

Email sending failed

我的php程序如下:

<?php
$to       = 'xyz@gmail.com'; /* here i added email id of person which i want to send mail */
$subject  = 'Testing sendmail.exe';
$message  = 'Hi, you just received an email using sendmail!';
$headers  = 'From: myid@gmail.com' . "\r\n" .
            'Reply-To: myid@gmail.com' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers))
    echo "Email sent";
else
    echo "Email sending failed";
?>

所以我没有找到我错的地方。谁能帮我解决这个问题。

谢谢。

【问题讨论】:

    标签: php email wamp


    【解决方案1】:

    你没有依赖任何类型的服务器 wamp,xammp 或者你只是使用这个代码的类 phpmailer 或者根据你修改

    <?php
    
    require 'class.phpmailer.php';
    $mail = new PHPMailer;
    
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup server
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'akkyverma';                            // SMTP username
    $mail->Password = 'password';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also        
    
    $mail->From = 'akkyverma@gmail.com';
    $mail->FromName = 'Mailer';
    $mail->addAddress('ankit_verma@example.net', 'ankit verma');  // Add a recipient
    $mail->addAddress('ankit_add@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;
    exit;
    }
    
    echo 'Message has been sent';
    

    只需使用像 $mail 这样的对象来发送电子邮件或发送具有多个 TO、CC、BCC 和 REPLY-TO 的电子邮件。查看 PHP 的经典邮件发送库Github

    【讨论】:

    • 以上 GitHub 链接上提供的 php 邮件程序
    • 谢谢@ankit verma。我遵循上面的事情。当我运行此脚本时,这给了我以下错误。警告:stream_socket_enable_crypto():此流不支持 C:\xampp\htdocs\sendmail\class.smtp.php 中的 SSL/加密,第 274 行消息无法发送。邮件程序错误:SMTP 连接()失败。请帮我一个。谢谢
    • 谢谢@ankit verma。我从 php.ini 文件中的 extension=php_openssl.dll 中删除了分号。它有效......非常感谢你
    【解决方案2】:

    您需要在您的WAMP setup 中启用OpenSSL 扩展。

    我看到你取消了这一行的注释:extension=php_openssl.dll 这很好,但显然带有 apache 2.4.4 的 Wampserver 发布时带有错误的 OpenSSL 文件!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 2013-12-19
      • 2015-07-19
      相关资源
      最近更新 更多