0

I want to send mail using php mail() function. but it is not working. tell me the mistake in code?if any correction in php.ini file should be there then also tell that.

here is my code:-

<!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
if($_POST['submit'])
{
    $subject = $_POST['subject'];
    $to = $_POST['receiver'];
    $message = $_POST['body'];
    $sentmail = mail($to, $subject, $message);
if($sentmail == 'true')
{
    echo 'Email successfully sent';
}
else
{
    echo 'Email is not successfully sent';
}
}
else
{
?>
<form action="mail_trial3.php" method="POST">
Enter the Receiver email ID:-
<input type="text" name="receiver" /><br /><br />
Enter the subject:-
<input type="text" name="subject" /><br /><br />
Enter the message body:-
<input type="text" name="body" /><br /><br />
<input type="submit" value="Send the mail" name='submit'/>
</form>
<?php
}
?>
</body>
</html>

Edited by Dani: Formatting fixed

5
Contributors
8
Replies
11
Views
5 Years
Discussion Span
Last Post by Biiim
0

1. Use code tags.
2. What is not working? Explain what happens?
3. Running on local or remote server?
4. Running on *nix or windows?

0

you are also use this condition and try in server not in localhost and use $header also

if(mail($to, $subject, $message))
{
echo 'Email successfully sent';
}
else
{
echo 'Email is not successfully sent';
}

0

reply for your orders:-
2. when I am running the code this error is occuring:-
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 C:\wamp\www\prj2\mail_trial3.php on line 16

3.I am running this on wamp server that is local server.

4. my operating system is window xp(in VMware workstation).

0

copy and past this code and try


<?php

if(isset($_POST) && !empty ($_POST["subject"]) ){
$subject = $_POST;
$to = $_POST;
$message = $_POST;

$from = 'mail@mail.com';

$headers = "From: ".$from."\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "\r\nX-Mailer: PHP/" . phpversion();

if(mail($to , $subject , $message , $headers )){

echo 'Email successfully sent';
}
else
{
echo 'Email is not successfully sent';
}


}
?>

0

Can i try mail function without the headers parameter? I think it is optional to use header.

0

do you have a mail server setup on your pc(localhost)?

you can download something like hmail - http://www.hmailserver.com/ if you dont have a mail server on your pc.

OR

just setup php.ini to connect to some mail account that you use, hopefully you have some email account around like a mail@ company email address?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.