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 ?
Asked
Active
Viewed 6,486 times
1
-
2What exactly are you trying to achieve with this? Sending E-Mail can be allowed but the server can be misconfigured so no E-Mail will be sent anyway, rendering your check pointless. What is your actual situation? – Pekka Dec 28 '11 at 11:04
-
i want to check mail() is supporting into client's server? – Kichu Dec 28 '11 at 11:06
-
2as said, being able to call `mail()` doesn't necessarily mean E-Mail is set up. This stuff is complex, there is no single check to find out. The best thing would be to send an actual E-Mail and see whether it arrives – Pekka Dec 28 '11 at 11:07
3 Answers
1
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";
}

Sudhir Bastakoti
- 99,167
- 15
- 158
- 162
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';
}
?>

Zul
- 3,627
- 3
- 21
- 35
-
but when iam using this code an error message is displayed "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in E:\wamp\www\promo\install\index.php on line 108" – Kichu Dec 28 '11 at 11:35
0
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());
}

Kathir
- 1,212
- 15
- 25