Forum Moderators: coopster

Message Too Old, No Replies

Email HTML using PHP

Submit a registration form using HTML and PHP

         

TheKG

4:03 pm on May 11, 2023 (gmt 0)

10+ Year Member Top Contributors Of The Month



I have an htm registration form which displays correctly. It submits to a php form to email the details to the person in charge of the event as well as the sender. However, it does not send an email at all. Any assistance with this is greatly appreciated.

HTM FORM

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">


<html>

<head>

<meta name="generator" content="Namo WebEditor">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Registration</title>

<style type="text/css">

<!--

body {
height:100%;
width:100%;
z-index:100;
}
table#reunion {

z-index:1;
}
table#reunion p {
font-family:Arial;
font-size:14pt;
margin-top:0;
margin-bottom:0;
}

-->
</style>

</head>

<body>

<form method="POST" action="../Registration.php" id="registration-form"><table id="registration" cellspacing="0">

<tr>
<td align="center">
<img src="../images/image.jpg" border="0"></td>
<td align="center" valign="middle"><p>Title</p></td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td align="center" colspan="2">
<p>Date of event</p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<td align="left" colspan="2">
<p>Event details</p>
</td>
</tr>


<tr><td>&nbsp;</td></tr>

<tr>
<td colspan="2">
Full Name <input type="text" name="name1"size="38%">
</td>
</tr>

<tr>
<td colspan="2">
Phone <input type="text" name="phone1" size="38%">
</td>
</tr>

<tr>
<td colspan="2">
Email <input type="text" name="email1" size="38%">
</td>
</tr>

<tr>
<td colspan="2">Choose your entree <input type="radio" name="entree1" value="Chicken">Chicken <input type="radio" name="entree1" value="Fish">Fish <input type="radio" name="entree1" value="Beef">Beef
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td colspan="2">
Full Name <input type="text" name="name2"size="38%">
</td>
</tr>

<tr>
<td colspan="2">
Phone <input type="text" name="phone2" size="38%">
</td>
</tr>

<tr>
<td colspan="2">
Choose your entree <input type="radio" name="entree2" value="Chicken">Chicken <input type="radio" name="entree2" value="Fish">Fish <input type="radio" name="entree2" value="Beef">Beef
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td colspan="2" align="center">
<p>Make check payable to</p>
<p> Mail Check to:</p>
<p>Name</p>
<p>address</p>
<p>city, state, zip</p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td colspan="2" align="center">
<input type="submit" value="Register">
</td>
</tr>

</form>

</table>


</body>



</html>


PHP FORM

<?php
$message = "";
if(isset($_POST['submit'])){
$to = "example@example.com"; // Your email address
$name = $_POST['name1'];
$from = $_POST['email1'];
$phone = $_POST['phone1'];
$message = "<!DOCTYPE html>
<head>

<style type="text/css">

<!--

body {
height:100%;
width:100%;
z-index:100;
}
table#reunion {

z-index:1;
}
table#reunion p {
font-family:Arial;
font-size:14pt;
margin-top:0;
margin-bottom:0;
}

-->
</style>


</head>

<body>

<form method="POST" enctype="text/plain">

<table id="reunion" cellspacing="0">

<tr>
<td align="center">
<img src="../images/image.jpg" border="0"></td>
<td align="center" valign="middle"><p>Title</p></td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td align="center" colspan="2">
<p>Date of event</p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<td align="left" colspan="2">
<p>Event details</p>
</td>
</tr>


<tr><td>&nbsp;</td></tr>

<tr>
<td colspan="2">
<p><".$_POST["name1"]."</p>
<p><".$_POST["entree1"]."></p>
<p><".$_POST["phone1"]."</p>
<p><".$_POST["email1"]."</p>
</td>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td colspan="2">
<p><".$_POST["name2"]."</p>
<p><".$_POST["entree2"]."></p>
<p><".$_POST["phone2"]."</p>
<p><".$_POST["email2"]."</p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td colspan="2" align="center">
<p>Make check payable to</p>
<p> Mail Check to:</p>
<p>Name</p>
<p>address</p>
<p>city, state, zip</p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>


</table>
</body>
</html>";

$subject = "Registration";

// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

$headers .= "From:" . $from . "\r\n";

$result = mail($to,$subject,$message,$headers);
if ($result) {
// $message = "Your Message was sent Successfully!";
echo '<script type="text/javascript">alert("Your Message was sent Successfully!");</script>';
echo '<script type="text/javascript">window.location.href = window.location.href;</script>';

}else{
// $message = "Sorry! Message was not sent, Try again Later.";
echo '<script type="text/javascript">alert("Sorry! Message was not sent, Try again Later.");</script>';
echo '<script type="text/javascript">window.location.href = window.location.href;</script>';
}
header('Location: Confirmation.html');
}
?>

phranque

9:09 pm on May 11, 2023 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



have you checked the error log for clues?

TheKG

4:28 pm on May 12, 2023 (gmt 0)

10+ Year Member Top Contributors Of The Month



After checking my error log, I made many changes and tested after each change. I now have no errors, but it still does not send emails. What am I doing wrong?

Here's the new php code:


<?php

$message = "";
if(isset($_POST['submit'])){
$to = "example@example.net"; // Your email address
$name1 = $_POST['name1'];
$emai11 = $_POST['email1'];
$phone1 = $_POST['phone1'];
$name2 = $_POST['name2'];
$entree2 = $_POST['entree2'];
$phone2 = $_POST['phone2'];
$email2 = $_POST['email2'];
$message = "<!DOCTYPE html>
<html>
<head>

</head>

<body>

<table id="reunion" cellspacing="0">

<tr>
<td align="center">
<img src="../images/image.jpg" border="0"></td>
<td align="center" valign="middle"><p>Title</p></td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td align="center" colspan="2">
<p>Date of event</p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<td align="left" colspan="2">
<p>Event details</p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td colspan='2'>
<p><?php echo $name1?></p>
<p><?php echo $entree1?></p>
<p><?php echo $phone1?></p>
<p><?php echo $email1?></p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td colspan='2'>
<p><?php echo $name2?></p>
<p><?php echo $entree2?></p>
<p><?php echo $phone2?></p>
<p><?php echo $email2?></p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td colspan="2" align="center">
<p>Make check payable to</p>
<p> Mail Check to:</p>
<p>Name</p>
<p>address</p>
<p>city, state, zip</p>
</td>
</tr>

<tr><td>&nbsp;</td></tr>


</table>
</body>
</html>";

$subject = "Contact Form Details";

// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

$headers .= "From:" . $email1 . "\r\n";

$result = mail($to,$subject,$message,$headers);
if ($result) {
// $message = "Your Message was sent Successfully!";
echo '<script type="text/javascript">alert("Your Message was sent Successfully!");</script>';
echo '<script type="text/javascript">window.location.href = "../Reservation_Complete.html";</script>';
}
else{
// $message = "Sorry! Message was not sent, Try again Later.";
echo '<script type="text/javascript">alert("Sorry! Message was not sent, Try again Later.");</script>';
echo '<script type="text/javascript">window.location.href = "/"Event.htm"</script>';
}

}
?>

phranque

5:04 pm on May 12, 2023 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



which $message was shown?

tangor

7:08 am on May 14, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Asking the obvious, is the mail server showing any errors in that log? Does it send email otherwise than from this particular script?

TheKG

2:10 pm on May 15, 2023 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thank you all for the suggestions. I had been working on this in the meantime to meet my deadline and, after much trial and error, it now works perfectly. Here is the code I am using.

<?php


$to = "example@example.com";

/* This section is where the script reads your form fields. */
$name1= $_REQUEST['name1'];
$email1= $_REQUEST['email1'];
$phone1= $_REQUEST['phone1'];
$entree1= $_REQUEST['entree1'];
$name2= $_REQUEST['name2'];
$email2= $_REQUEST['email2'];
$phone2= $_REQUEST['phone2'];
$entree2= $_REQUEST['entree2'];


$subject = "Event Registration";

$header = "From: \"$name1\" <$email1>\r\n";
$header .= "Cc: $email1 \r\n";
$header .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$body = "<html>
<meta name=\"viewport\" content=\"width=device-width\" />
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />

</head>

<body>

<table id='event' cellspacing='0'>

<tr>
<td align='center'>
<td align='center'><Event Title</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td align='center'>
<p>Date of event</p>
<p>Place of event</p>
<p>address</p>
<p>city, state, zip</p>
</td>
</tr>

<td align='center'>
Event details
</td>
</tr>

<tr>
<td align='center'>
<p>registration deadline</p>
<p>Prices</p>
</td>
</tr>

<tr>
<td colspan='2'>
<p>$name1</p>
Entree Selection $entree1</p>
<p>$phone1</p>
<p>$email1</p>
</td>
</tr>

<tr>
<td colspan='2'>
<p>$name2</p>
Entree Selection $entree2</p>
<p>$phone2</p>
<p>$email2</p>
</td>
</tr>


</table>


</html>";

(mail($to, $subject, $body, $header)) ;
echo "Looking forward to seeing you, " . $name1 . "! An email has been sent to event coordinator and a copy to you. Be sure to check your spam/junk folders.";

?>

phranque

5:56 pm on May 15, 2023 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



what was the problem and how did you fix it?

phranque

9:32 pm on May 15, 2023 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Be sure to check your spam/junk folders.

was this the "problem" to be solved?