PDA

View Full Version : Send Mail


illa_arm
04-20-2007, 07:31 PM
im just trying to send mail by using a very simple php function mail() but it is not working.the format is



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





I think there is something wrong with php.ini setting..maybe something to do with SMTP settings.. i want to send email FROM either hotmail , gmail , or yahoo or any other web based email because i dont know my ISP smtp setting..so can anyone please help me , where to make change and what to make change ?

davidj
04-20-2007, 08:08 PM
its incorrect...

you have your mail function in an IF statement?

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

try this...

NOTE: i have an IF which is checking your $to var. This will always be true so will run every time the page loads. You may have to visit your logic again

$to = "email@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

if ($to){
mail($to, $subject, $body);
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}


you need to understand the syntax

illa_arm
04-20-2007, 08:14 PM
thanks..

but i got some error here..i think that i cannot set up the php.ini configuration correctly:(

here the error :
Warning: mail() [function.mail (http://localhost/eqes/try/function.mail)]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Program Files\xampp\htdocs\eQes\try\email4.php on line 14

davidj
04-20-2007, 08:17 PM
you have to run that script from a php supporting host which allows the mail() function

you cant run it localy as it wont work