Welcome to WebmasterWorld Guest from 54.163.23.73

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

how to send mails using mail() in php

     

ravii

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

5+ Year Member



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]

cameraman

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

WebmasterWorld Senior Member 5+ Year Member



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?

Mahabub

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

5+ Year Member



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

CWI Tech Guy

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

5+ Year Member



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 ?

 

Featured Threads

Hot Threads This Week

Hot Threads This Month