Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

email - How to check if PHP mail() is enabled?

I need to install a PHP site on a Microsoft server. For some reason the host isn't allowing the site to send e-mails. The host has sent me a code sample... which didn't work.

Is there a way to check if the server allows sending of e-mails through the php mail() function?

At this stage it is all about finger pointing and I need some proof here to show the client that the host is at fault.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To check if the mail function is enabled on your server or PHP install, use

<?php
if ( function_exists( 'mail' ) )
{
    echo 'mail() is available';
}
else
{
    echo 'mail() has been disabled';
}
?>

to check if it sending mail

<?php 

$email = "[email protected]";
$subject =  "Email Test";
$message = "this is a mail testing email function on server";


$sendMail = mail($email, $subject, $message);
if($sendMail)
{
echo "Email Sent Successfully";
}
else

{
echo "Mail Failed";
}
?>

If the mail() function exist but mails not going, check if a mail transport agent (MTA)such as sendmail or postfix is installed on your server

If you on Linux :

Try;

$ dpkg -S `which sendmail`

to install sendmail on Ubuntu;

sudo apt-get install sendmail

https://www.digitalocean.com/community/questions/setting-up-email-with-sendmail


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...