Page 1 of 1

php form submit code - (can't get email)

Posted: Wed May 05, 2010 9:52 am
by dae666
Hi guys,
I was wondering if anyone could help me with this form issue on my site.

On my website I have the following code on a form submit, that should send me an email, but i only get the 'cc' email and not the original email. (the gmail address works the other one doesnt)

I have no knowledge of php, just trying to fix what someone else has done...!

Any advice would be appreciated

many thanks Damian.

The code is below:

if($valid == 1)
{
$to = "info@azofcreatives.com";

$subject = 'Contact Mail';

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$email. "\r\n";
$headers .= 'Cc: dayellis@gmail.com' . "\r\n";

$message .= "<strong>Name = </strong>".$fname."<br>";
$message .= "<strong>Tel = </strong>".$tel."<br>";
$message .= "<strong>Email = </strong>".$email."<br>";
$message .= "<strong>Comments = </strong>".$comments."<br>";
@mail($to, $subject, $message,$headers);
header('Location: about_us.php?msg=You message has been received');

Re: php form submit code - (can't get email)

Posted: Wed May 05, 2010 2:30 pm
by minorDemocritus
Use [ syntax=php ] bbcode to enclose your code. Please.

Re: php form submit code - (can't get email)

Posted: Thu May 06, 2010 7:05 am
by dae666
Hello MinorD,

Thanks for replying to my message.
Can you explain what you mean by this please. If I add [ syntax=php ] to the code will it fix the email problem?

here is the entire code string:

Many thanks again, if you could reply that would be much appreciated...!!!

<?php
session_start();
function checkemailvalidity($email) {

$regexp = "/^[^0-9_.-][A-z0-9_.]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";

if(preg_match($regexp,$email))
{
return true;
}
else
return false;
}
if($_POST['submit'])
{
$valid = 1;
$fname = $_POST['fname'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$comments = $_POST['comments'];

if($fname == '')
{
$valid = 0;
$namemsg = "enter name";
}
if($tel == '')
{
$valid = 0;
$telmsg = "enter tel";
}
if($email == '')
{
$valid = 0;
$emailmsg = "enter email";
}
if($email)
{
if(!checkemailvalidity($email))
{
$valid = 0;
$emailmsg = "enter valid email";
}
}

if($valid == 1)
{
$to = "info@azofcreatives.com";

$subject = 'Contact Mail';

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$email. "\r\n";
$headers .= "Cc: info@azofcreatives.com" . "\r\n";
$headers .= "From: no-reply@azofcreatives.com" ."\r\n";

$message .= "<strong>Name = </strong>".$fname."<br>";
$message .= "<strong>Tel = </strong>".$tel."<br>";
$message .= "<strong>Email = </strong>".$email."<br>";
$message .= "<strong>Comments = </strong>".$comments."<br>";
@mail($to, $subject, $message,$headers);
header('Location: index.php?msg=Your message has been received');



}
}

?>

Re: php form submit code - (can't get email)

Posted: Thu May 06, 2010 7:38 am
by asai
No, he means that you should post your code with

Code: Select all


Then your code will look like this:
[syntax=php]<?php
session_start();
function checkemailvalidity($email) {

$regexp = "/^[^0-9_.-][A-z0-9_.]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";

if(preg_match($regexp,$email))
{
return true;
}
else
return false;
}
if($_POST['submit'])
{
$valid = 1;
$fname = $_POST['fname'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$comments = $_POST['comments'];

if($fname == '')
{
$valid = 0;
$namemsg = "enter name";
}
if($tel == '')
{
$valid = 0;
$telmsg = "enter tel";
}
if($email == '')
{
$valid = 0;
$emailmsg = "enter email";
}
if($email)
{
if(!checkemailvalidity($email))
{
$valid = 0;
$emailmsg = "enter valid email";
}
}

if($valid == 1)
{
$to = "info@azofcreatives.com";

$subject = 'Contact Mail';

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$email. "\r\n";
$headers .= "Cc: info@azofcreatives.com" . "\r\n";
$headers .= "From: no-reply@azofcreatives.com" ."\r\n";

$message .= "<strong>Name = </strong>".$fname."<br>";
$message .= "<strong>Tel = </strong>".$tel."<br>";
$message .= "<strong>Email = </strong>".$email."<br>";
$message .= "<strong>Comments = </strong>".$comments."<br>";
@mail($to, $subject, $message,$headers);
header('Location: index.php?msg=Your message has been received');



}
}

?>

Re: php form submit code - (can't get email)

Posted: Thu May 06, 2010 10:01 am
by dae666
okay, thanks for explaining that Asai.

hopefully someone will know how I can get it to work...!!!

Re: php form submit code - (can't get email)

Posted: Thu May 06, 2010 12:48 pm
by minorDemocritus
Your code looks right. Try removing the @ sign before the mail() function, and turn up your error reporting. This will give you a lot more information about what's failing.