简体   繁体   English

PHP mail()不发送电子邮件

[英]PHP mail() doesn't send e-mail

I have a question for all you out there. 我有一个问题要问大家。

I've noticed that my php mail isn't sent anymore. 我注意到我的php邮件不再发送了。 So I looked into it to determine what the problem is but I can't seem to find it. 因此,我调查了一下以确定问题所在,但似乎找不到。

This is the case: 就是这种情况:

In powershell 3 (server 2012)I use the following command: 在Powershell 3(Server 2012)中,我使用以下命令:

send-MailMessage -SmtpServer smtp.versatel.nl

and after giving the to e-mail address, a subject and a from address it sends the mail without any problem. 在给收件人电子邮件地址,主题和发件人地址之后,它可以毫无问题地发送邮件。

The code in the PHP file is: PHP文件中的代码是:

INI_SET("SMTP", "smtp.versatel.nl");
$success = mail($to, $subject, $body, $header);

preg_match("/\d+/", $error["message"], $error);
if(!$success){$this->sFoutmelding ='Email is niet verstuurd.'.print_r($error);}

In the php.ini I disabled the default ini settings: 在php.ini中,我禁用了默认的ini设置:

mail function]
; For Win32 only.
; SMTP = Smtp.versatel.nl
; smtp_port = 25

But still I get an error that the mail isn't sent: 但是仍然收到未发送邮件的错误消息:

Array ( )
Email is niet verstuurd.1

Why doesn't php send the mail when powershell does this perfectly? 为什么Powershell完美地做到了,PHP为什么不发送邮件? Any ideas are welcome, I have searched on and off the whole week over the internet, but i can't find an answer. 任何想法都可以接受,我整周都在互联网上搜索过,但我找不到答案。

*edit *编辑

I tried the var_dump and it gives, as expected, only a 'FALSE'. 我尝试了var_dump,并且按预期提供的只是“ FALSE”。

Also the change in 'localhost' didn't do the trick. 同样,'localhost'中的更改也无法解决问题。 Still searching... 仍在搜索中...

Its working, but still no explonation why :-) So if someone knows why, I like to know it too :-) 它的工作原理,但仍然没有理由为什么:-)所以,如果有人知道为什么,我也想知道它:-)

It still uses the same smtp server as without the phpmailer class. 它仍然使用与没有phpmailer类相同的smtp服务器。 So the only thing I can think off is the fact that PHPmailer creates a different, more widly excepted, mail header than the default one of PHP. 因此,我唯一能想到的是,与默认的PHP相比,PHPmailer创建了一个不同的,更加奇怪的邮件标头。

I added the following code and class PHP mailer: 我添加了以下代码和类PHP邮件程序:

$success = $this->mail_attachment($to, $subject, $body);

protected function mail_attachment($mailto, $subject, $message) {
require_once("../PHPMailer/class.phpmailer.php");
//$file = $path.$filename;
$mail = new PHPMailer();

$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "smtp.versatel.nl"; // SMTP server

$mail->From     = "noreply@provider.foo";
$mail->FromName = "Sendername";
$mail->AddAddress($mailto);


$mail->Subject  = $subject;
$mail->Body     = $message;
$mail->WordWrap = 75;
//$mail->AddAttachment($file);

    if(!$mail->Send()) {
      echo 'Bevestigings e-mail is niet verzonden.';
      echo 'Mailer error is: ' . $mail->ErrorInfo;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM