How can i check mail sending is allowed in client's server

会有一股神秘感。 提交于 2019-12-10 11:41:51

问题


In my site there have some mailing options.Here iam sending an html mails. So i need to check wheather my client's server support the mail function or not. How can i check this? If there is any php code for this ?


回答1:


so you want to check mail() is supporting into client's server?

if(function_exists('mail'))
{

}

But, i'm sure this method is not recommended, the best way to check, send an empty message to your self:

<?php
if(mail($to,$subject,$message) != false)
{
   echo 'You can send email';
}
?>



回答2:


You can only check whether mail is sent or not:


$message = "Line 1\nLine 2\nLine 3";

// Send
if(mail('YOUR_EMAIL_HERE@example.com', 'My Subject', $message)) {
  echo "Sent";
}
else {
  echo "Not Sent";
}




回答3:


Try below code.


if(mail('TEST_ACCOUNT@gmail.com','test','content') != false)
{
   echo 'You can send email from this server';
}else{
    print_r(error_get_last());
}



来源:https://stackoverflow.com/questions/8655035/how-can-i-check-mail-sending-is-allowed-in-clients-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!