Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 邮件不是用wamp发送的_Php_Email_Wamp - Fatal编程技术网

Php 邮件不是用wamp发送的

Php 邮件不是用wamp发送的,php,email,wamp,Php,Email,Wamp,我想使用mail函数从我的php脚本发送邮件。所以我安装了Wamp 并且在sendmail.ini和php.ini中使用 当我运行php程序时,它给出: 电子邮件发送失败 我的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

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

并且在
sendmail.ini
php.ini
中使用

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

电子邮件发送失败

我的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";
?>

所以我并没有走错方向。有人能帮我吗


谢谢。

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

您需要在
WAMP设置中启用
OpenSSL
扩展


我看到您取消了这一行的注释:
extension=php_openssl.dll
,这很好,但显然带有Apache2.4.4的Wampserver发布了错误的openssl文件

php邮件程序可在上述GitHub链接上获得谢谢@ankit verma。我遵循上述原则。当我运行这个脚本时,这给了我以下错误。警告:无法发送第274行消息的C:\xampp\htdocs\sendmail\class.smtp.php中的流\u套接字\u enable\u crypto():此流不支持SSL/crypto。邮件程序错误:smtp connect()失败。请帮我拿一个这个。谢谢你,谢谢你@ankit verma。我从php.ini文件中的extension=php_openssl.dll中删除了分号。它是有效的。。。多谢各位