Php发送mail()不起作用

时间:2015-09-15 03:51:54

标签: php email

我正在使用免费托管of this link,我尝试使用php发送mail(),但它不起作用..这是我的代码:

<?php
      if(mail('example@yahoo.com','from mail','your subscription is almost over, you need to renew', 'sample header')){
          echo 'mail sent';
      }else{echo 'not sent';}
?>

我也试过在localhost中使用它并在php.ini中编辑我的SMTP。是否有任何方式在PHP中发送邮件,也将在免费托管中工作?

1 个答案:

答案 0 :(得分:0)

// mail(to,subject,message,headers,parameters);
$to = 'example@yahoo.com';
$subject = 'Subscription Information';
$message = 'your subscription is almost over, you need to renew';
$headers = "From: info@mydomain.com" . "\r\n" .
            "CC: you_too@mydomain.com";

$mail =mail($to,$subject,$message, $headers);

if(isset($mail))
{
    echo 'mail sent';
}
else
{
    echo 'not sent';
}

image

PHP mail() Function