homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

how to send mails using mail() in php

 6:40 am on Dec 24, 2008 (gmt 0)


can any tell me how to send mails from site using mail() in php

do we need to change in the php.ini
these are in php.ini

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = me@example.com

and i tried with this example it is giving me the message saying "message successfully sent" but there is no mail in my inbox

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

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

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

[edited by: eelixduppy at 6:41 am (utc) on Dec. 24, 2008]
[edit reason] removed specifics [/edit]



 3:19 pm on Dec 24, 2008 (gmt 0)

It's giving you the message because you're checking that $to is not null, which it isn't.
mail() returns a boolean value indicating whether the mail was successfully sent - test for that.

Have you looked at your server's error logs?


 5:18 pm on Dec 24, 2008 (gmt 0)

Dear ravii,

You have to mention SMTP. SMTP must not be localhost also check SMTP port is opened in your PC or in server.


CWI Tech Guy

 9:54 am on Jan 7, 2009 (gmt 0)

Actually Mahabub, the localhost may be correct as most of my servers are setup in such a way. They require that anything being sent from a form or script that cannot authenticate use localhost as the SMTP server.

Also, have you attempted to send mail to address outside your domain ?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved