Ezilon.com - Target Your Audience, be Seen in Your Region

PHP send email script

He has: 107 posts

Joined: Mar 2006

Hi,

It seems that no matter what PHP script I use to send an email it won't work, is this something to do with the server?

The most basic code I have tried is the following:

Can anyone see why this might not work?

Thanks,

$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("Message successfully sent!");
} else {
echo("Message delivery failed...");
}

teammatt3's picture
Moderator

He has: 1,809 posts

Joined: Sep 2003

Which message are you getting? If you get the successful message, your server might be blacklisted by the recipient. If you get the failed message, your server probably isn't setup right, and you should talk with your host about it.

He has: 107 posts

Joined: Mar 2006

I don't get any message lol I think my host provides smtp settings but not sure how to set them up or whether they need to be setup? Thanks, I will ask the hosting company about it.

Sponsor

He has: 470 posts

Joined: Sep 2006

I use htmlMimeMail to send all my email from PHP. It allows you to use remote (or local) smtp servers which will bypass any host restriction on the local mail() function. This class also supports mail in HTML and text format as well as attachments.

teammatt3's picture
Moderator

He has: 1,809 posts

Joined: Sep 2003

That's a neat little class. I've tried a bunch like it and they all fail when I try to use gmail as the SMTP server. This one worked the first time I tried it. Sweet Smiling

He has: 336 posts

Joined: Nov 2005

Your code looks fine, so it might be something to do with your host and the server outgoing smtp config.

And of course I presume you have double checked your email address in $to Laughing out loud