Page 1 of 1

php Email code not working

Posted: Wed Nov 12, 2008 3:50 am
by Narcud
Hi, I am using the following code to send an email from a Feedback.htm form
- when it is opened in the browser it then takes me to the Thanks.htm page as expected, but I never receive an email. There is no error message from the mail.php code below when it is ran
Can anyone suggest where the error may be ?

thanks
Nic

<?php

$address = "myaddress@hotmail.co.uk";
$firstname = $_POST['firstname'];
$secondname = $_POST['secondname'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$subject = "Feedback left by ".$name.".";
$message = "The following comment was left to you by ".$firstname." ".$secondname."(".$email.") on ".date("d/m/Y").".
".$comments.".";
$headers = "From: ".$email."";
@mail($address,$subject,$message,$headers);
header("Location:Thanks.htm");
?>

Re: php Email code not working

Posted: Wed Nov 12, 2008 4:26 am
by novice4eva
don't do

Code: Select all

 
@mail($address,$subject,$message,$headers);/* RATHER JUST do mail() without @*/
 


as it will suppress any errors returned by that particular function. If that doesn't show up anything... I never had to correct it because there is always a system admin to help: but i think you have to make corrections in your PHP.ini file too, setting SMTP or something of that nature :crazy: . To enable error messaging add this at the top (you may already know this but then also)

Code: Select all

 
    ini_set('display_errors', 1);
    ini_set('error_reporting', E_ALL);
 

Re: php Email code not working

Posted: Wed Nov 12, 2008 5:58 am
by amit007
You can use below function to send mail:

mail(to,subject,message,headers,parameters);

Re: php Email code not working

Posted: Mon Nov 17, 2008 9:11 am
by Narcud
Hi thanks for the repsonse. I have updated my code to :

<?php
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
$address = "myaddress@hotmail.co.uk";
$firstname = $_POST['firstname'];
$secondname = $_POST['secondname'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$subject = "Feedback left by ".$firstname.".";
$message = "The following comment was left to you by ".$firstname." ".$secondname."(".$email.") on ".date("d/m/Y").".".$comments.".";
$headers = "From: ".$email."";
mail($address,$subject,$message,$headers);
header("Location:Thanks.htm");
?>
and get the following errors


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:\Inetpub\vhosts\studentweb.stockport.ac.uk\subdomains\astudent\httpdocs\mail.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\studentweb.stockport.ac.uk\subdomains\astudent\httpdocs\mail.php:9) in C:\Inetpub\vhosts\studentweb.stockport.ac.uk\subdomains\astudent\httpdocs\mail.php on line 13


any ideas ?

Thanks

Nic

Re: php Email code not working

Posted: Mon Nov 17, 2008 10:55 am
by waqas_punjabian
Buddy,

You are testing your email script on your localhost, where you have not configured the mailing server (smtp, pop3).
When you will run this code on some online host, this will work fine.


Waqas