-1

I'm having trouble figuring out why my contact form isn't working. I'm relatively new to PHP and from what I can see, everything is linked, but when I go to send the email, nothing is sent to the designated delivery address. Any help would be appreciated!! Thank you!! My code is below:

HTML

<table width="400" border="0" align="left" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="mail.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Message</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

PHP

<?php

// Contact subject
$subject ="$subject"; 

// Details
$message="$detail";

// Mail of sender
$mail_from="$customer_mail"; 

// From 
$header="from: $name <$mail_from>";

// Enter your email address
$to ='jordanmcowan@gmail.com';
$submit=mail($to,$subject,$message,$header);

// Check, if message sent to your email 
// display message "We've recived your information"
if($submit){
echo "Thank you for contacting us at Allstar Therapies, Inc.<br /> We will be in touch shortly!";
}
else {
echo "ERROR";
}
?>
JCow
  • 1
  • When you submit the form, what do you get? Blank white page? White page with text (if so, which text?) - or what? Firebug will help you debug this - – rm-vanda Jan 13 '15 at 16:37
  • Do you enter in "ERROR" or in "Thank you..." part ? You don't need to enclose $var in "" ! – Spoke44 Jan 13 '15 at 16:37

5 Answers5

1

Your PHP Code seems wrong to me. This is a corrected version

<?php

// Contact subject
$subject = $_POST['subject'];

// Details
$message = $_POST['detail'];

// Mail of sender
$mail_from = $_POST['customer_mail'];

// From 
$header = "from: " . $_POST['name'] . "<" . $_POST['customer_mail'] . ">";

// Enter your email address
$to = 'jordanmcowan@gmail.com';
$submit = mail($to, $subject, $message, $header);

// Check, if message sent to your email 
// display message "We've recived your information"
if ($submit) {
    echo "Thank you for contacting us at Allstar Therapies, Inc.<br /> We will be in touch shortly!";
} else {
    echo "An error has been encountered while sending your message. We sincerely apologize and ask you to try again. If that fails as well, please contact us at XYZ-Y234-SADF";
}

The variables haven't been initialized. Please note that these symbols: "" mark the beginning and the end of a string.

Simon
  • 21
  • 3
0

You haven't set your PHP variables (IE $subject) to your post variables yet. Try changing your PHP variables to use the $_POST variables.

<?php

// Contact subject
$subject = $_POST['subject'];

// Details
$message= $_POST['detail'];

// Mail of sender
$mail_from= $_POST['customer_mail']; 

// From 
$header="from: {$_POST['name']} <{$_POST['mail_from']}>";

// Enter your email address
$to ='jordanmcowan@gmail.com';
$submit=mail($to,$subject,$message,$header);

// Check, if message sent to your email 
// display message "We've recived your information"
if($submit){
echo "Thank you for contacting us at Allstar Therapies, Inc.<br /> We will be in touch shortly!";
}
else {
echo "ERROR";
}
?>
Ding
  • 3,065
  • 1
  • 16
  • 27
0

These lines are wrong:

// Contact subject
$subject ="$subject"; 

// Details
$message="$detail";

// Mail of sender
$mail_from="$customer_mail"; 

// From 
$header="from: $name <$mail_from>";

You're trying to assign the variables to themselves. Try:

$subject = $_POST['subject'];
$message = $_POST['detail'];

etc.

Edward Yu
  • 400
  • 1
  • 4
  • 13
0

You need to use $_POST variable:

// Contact subject
$subject = isset($_POST["subject"]) ? ($_POST["subject"]) : ""; 
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
0

You can access to POST parametars by $_POST / GET parametars by $_GET. First check if your redirect works correct. type: echo "welcome"; in mail.php

If redirect works the print all Post parametars: print_r($_POST);

Last you can get one by one

$variable = $_POST['input_name_from_form'];

Hope this is solution for your problem

zafirov
  • 392
  • 1
  • 3
  • 18