PHP send email script

They have: 105 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 = "[email protected]";
$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

He has: 2,102 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.

They have: 105 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.

pr0gr4mm3r's picture

He has: 1,502 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

He has: 2,102 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

greg's picture

He has: 1,581 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

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.