...

View Full Version : PHP Mail



yasirjamal
03-12-2009, 03:04 PM
Dear Friends,

I am getting problem during sending email. Before the same code was working. But now i am receiving this error.

Notice: Undefined variable: fname_field in E:\Sites\Single5\starlinks\webroot\mailer.php on line 6

Notice: Undefined variable: headers in E:\Sites\Single5\starlinks\webroot\mailer.php on line 6

Notice: Undefined index: message in E:\Sites\Single5\starlinks\webroot\mailer.php on line 12

Notice: Undefined index: lastname in E:\Sites\Single5\starlinks\webroot\mailer.php on line 13

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 E:\Sites\Single5\starlinks\webroot\mailer.php on line 31

My php mail script is below please have a look.



<?php
if(isset($_POST['submit'])) {

$to = "yasir.jamal.co.cc";
$subject = "From DSR Website";
$headers.= "From: $fname_field\r\n";
$fname_field = $_POST['firstname'];
$lname_field = $_POST['lname'];
$city = $_POST['city'];
$occupation = $_POST['occupation'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$option = $_POST['lastname'];
$comment = $_POST['comment'];
$telephone = $_POST['telephone'];
$mob = $_POST['mobile'];
$dropdown = $_POST['interstedin'];

$body = "
First Name: $fname_field\n
Last Name: $lname_field\n
E-Mail: $email_field\n
Intersted In: $dropdown\n
City : $city\n
Occupation : $occupation\n
Telephone : $telephone\n
Mobile : $mob\n
Message: $comment\n";

if (mail($to, $subject, $body, $headers)) {
header ("Location: http://www.yasirjamal.com/Email sent.html");
}

} else {
echo "blarg!";
}
?>

_Aerospace_Eng_
03-12-2009, 03:17 PM
They are notices not errors.

<?php
if(isset($_POST['submit'])) {

$fname_field = $_POST['firstname'];
$lname_field = $_POST['lname'];
$city = $_POST['city'];
$occupation = $_POST['occupation'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$option = $_POST['lastname'];
$comment = $_POST['comment'];
$telephone = $_POST['telephone'];
$mob = $_POST['mobile'];
$dropdown = $_POST['interstedin'];

$body = "
First Name: $fname_field\n
Last Name: $lname_field\n
E-Mail: $email_field\n
Intersted In: $dropdown\n
City : $city\n
Occupation : $occupation\n
Telephone : $telephone\n
Mobile : $mob\n
Message: $comment\n";

$to = "yasir.jamal.co.cc";
$subject = "From DSR Website";
$headers = "From: $fname_field\r\n";

if (mail($to, $subject, $body, $headers)) {
header ("Location: http://www.yasirjamal.com/Email sent.html");
}

} else {
echo "blarg!";
}
?>
That should take care of the first two notices. Those variables weren't defined yet when you tried to use them. As to the message and last_name notices it means those items didn't post from you form. Make sure you have inputs in your form with name="message" and name="last_name".

The warning you get about stmp means you need to enable sendmail in your php.ini file.

yasirjamal
03-12-2009, 04:00 PM
Dear friend,

i am new to php. i dont no how to set smtp. Now i am gegting only 1 error brfore i am getting 6 error.

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 E:\Sites\Single5\starlinks\webroot\mailer.php on line 29

_Aerospace_Eng_
03-12-2009, 05:02 PM
Are you hosting a site on your own system or do you have a shared host that you are using?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum