Hi, I''m trying to learn how to send emails to registered users with php mail function. Been online a lot and getting confused. I was wondering if anyone could explain how the set up is done and what is needed to accomplish this task. Any input on this topic would be appreciated.
Thankyou.

Recommended Answers

All 11 Replies

What code are you using at the moment and what errors (if any) does it return?

<?php
$to = 'myemail@aol.com';
$subject = 'Hello from website!';
$from = 'localhost';
$message = 'Hell Yah!!';

if (mail($to, $subject, $message, "From:$from"))
echo 'sent mail!';
else 'F^!*&#';
?>
Error is:
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

I'm not sure why you are sending from localhost. That may be the problem.

I was having a problem with email a while back. Can't remember the error message.

This code seems to work.

Anyway, you might give it a try.

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <your.email@isp.com>" . "\r\n";

// More headers you can add.

$headers .= "Bcc:   <your.other.email@isp.com>" . "\r\n";

$to = 'myemail@aol.com';
$subject = 'Hello from website!';
$message = 'Hell Yah!!';

mail($to,$subject,$message,$headers);

I hope this works for you!

Larry

Hi Dave,

Just read your post on passwords. I think that answer to your problem was correct. You don't have a mail server on your localhost. Or it's not set up correctly. Can you test this on an external server?

Larry

I just singed up with a web hosting company. I'll have to learn how to use that before I can test emails.
Open to any comments about the configuration though, or any good tutorials or books.

Hi Dave,

Although you can probably find a book on this. I hate to see you incur the expense when it's really a very simple procedure. You can probably get all of this help from the technical aid at the hosting company, which is very little. First you need to find the ftp (file transfer protical) in the host companie's website. Then you upload your files into the root directory. You can make sub directories in that root directory just like you would on your hard drive at home. But of course make sure there's an index.php file in the root directory so everyone can't see all of your code. That's pretty much it.

If you don't like the hosting companie's ftp you can always find some free versions out there by doing a Google search. I personally like coffee cup.

I hope this helps,

Larry

PS - any major hosting company will have the PHP mail turned on. If not then you need to ask them to do so for you

Hi Dave,

Like Larry said, you will need to use a web host as PHP mail proberly isnt enabled on your localhost.

Try something like:

<?php
$eol = "\r\n";
$to = ""; //the recipitant
$subject = ""; // the subject
$message = ""; // the message
$headers = "From: Your name<no-reply@your-domain>$eol";
$headers = "MIME-Version: 1.0$eol";
$headers .= "Content-type:text/html;charset=iso-8859-1$eol";
	
if(@mail($to, $subject, $message, $headers)) {
echo "SENT";
}

else {
echo "NOT SENT";
}
?>

Hi diskhub,

I was wondering if you tell me what the @ before php functions does? I see it around a lot.

Thanks,

Larry

Hi diskhub,

I was wondering if you tell me what the @ before php functions does? I see it around a lot.

Thanks,

Larry

Hi Larry,

The @ symbol before a function is a error supressor e.g.

@mail(.........);

would stop:

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

from showing in the browser.

Ah, very good! Thanks for the reply!

Larry

Thanks for info.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.