Welcome to WebmasterWorld Guest from 54.234.244.30

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

how to send mails using mail() in php

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

New User

5+ Year Member

joined:Sept 5, 2008
posts: 30
votes: 0


hello,

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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$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>");
}
?>
</body>
</html>

[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)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Jan 16, 2007
posts:914
votes: 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)

Junior Member

5+ Year Member

joined:Dec 7, 2008
posts:77
votes: 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.

THanks
Mahabub

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

New User

5+ Year Member

joined:Jan 4, 2009
posts: 18
votes: 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 ?

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members