0

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

并设置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";
?>

所以我没有得到我错的地方。谁可以帮我这个事。

谢谢你。

4

2 回答 2

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';

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

于 2013-10-11T06:50:28.620 回答
0

您需要OpenSSLWAMP setup.

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

于 2013-11-28T06:29:14.820 回答