邮件不是用wamp发送的

时间:2013-10-11 06:34:29

标签: php email wamp

我想使用mail function从我的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";
?>

所以我没有得到我错的地方。任何人都可以帮助我。

谢谢。

2 个答案:

答案 0 :(得分:0)

你没有依赖任何类型的服务器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';

只需使用LIke $ mail对象发送电子邮件或发送包含多个TO,CC,BCC和REPLY-TO的电子邮件。检查PHP Github

的经典电子邮件发送库

答案 1 :(得分:0)

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

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