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");
?>
php Email code not working
Moderator: General Moderators
- novice4eva
- Forum Contributor
- Posts: 327
- Joined: Thu Mar 29, 2007 3:48 am
- Location: Nepal
Re: php Email code not working
don't do
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
. To enable error messaging add this at the top (you may already know this but then also)
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
Code: Select all
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
Re: php Email code not working
You can use below function to send mail:
mail(to,subject,message,headers,parameters);
mail(to,subject,message,headers,parameters);
Re: php Email code not working
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
<?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
-
waqas_punjabian
- Forum Commoner
- Posts: 67
- Joined: Wed Aug 10, 2005 9:53 am
Re: php Email code not working
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
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