Jump to content

PHP Mailer Help


Conrad79

Recommended Posts

Hey, sorry I'm new to php scripting or coding in general, I'm trying to put a mail form on my website and have it where when they put there information in and submit it sends me an email with there info in it. However, every time I send a test. I'm getting an email, but it doesn't have any of the information in it. Please help.

Thank You.

 

 

<?php

 

/* Subject and Email Variables */

 

$emailSubject = 'Contact Info!';

$webMaster = 'AAPemails@gmail.com';

 

/* Gathering Data Variables */

 

$fnameField = $_POST['fname'];

$lnameField = $_POST['lname'];

$emailField = $_POST['email'];

 

$body = <<<EOD

<br><hr><br>

First Name: $fname <br>

Last Name: $lname <br>

Email: $email <br>

EOD;

 

$headers = "From: $email\r\n";

$headers .= "Content-type: text/html\r\n";

$success = mail($webMaster, $emailSubject, $body, $headers);

 

/* Results rendered as HTML */

 

 

 

$theResults = <<<EOD

 

<html>

<head>

<title>AAP Newsletter</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">

<!--

body {

background-color: #f1f1f1;

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 12px;

font-style: normal;

line-height: normal;

font-weight: normal;

color: #666666;

text-decoration: none;

 

-->

</style>

</head>

 

<div>

<div align="left">Thank you for your time. You will recieve an email soon.</div>

</div?

</body>

</html>

EOD;

echo "$theResults";

 

?>

 

Link to comment
Share on other sites

You're not using the same variable that you defined.

$fnameField = $_POST['fname'];
$lnameField = $_POST['lname'];
$emailField = $_POST['email'];

$body = <<<EOD
<br><hr><br>
First Name: $fname <br>
Last Name: $lname <br>
Email: $email <br>
EOD;
You should be developing with error reporting on, and you would have seen something like this. Put this at the top of your script before anything else:
ini_set('display_errors', 1);
error_reporting(-1);
Link to comment
Share on other sites

Well i tried that and its still not working :(

 

<?php
 
/* Subject and Email Variables */
 
$emailSubject = 'Contact Info!';
$webMaster = 'AAPemails@gmail.com';
 
/* Gathering Data Variables */
 
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
 
$body = <<<EOD
<br><hr><br>
First Name: $fname <br>
Last Name: $lname <br>
Email: $email <br>
EOD;
 
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
 
/* Results rendered as HTML */
 
 
 
$theResults = <<<EOD
 
<html>
<head>
<title>AAP Newsletter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
 
-->
</style>
</head>
 
<div>
<div align="left">Thank you for your time. You will recieve an email soon.</div>
</div?
</body>
</html>
EOD;
echo "$theResults";
 
?>
Link to comment
Share on other sites

This is the form that you fill out.

 

<body>
 
<div class="container">
  <div class="header"><!-- end .header --><a href="index.html"><img src="AAP Header.png" alt="Insert Logo Here" name="Insert_logo" width="960" height="175" id="Insert_logo" style="background-color: #FFFFFF; display: block;" /></a></div>
  <div class="sidebar1">
    <ul class="nav">
      <li><a href="why_buy_from_us.html">Why buy from us?</a></li>
      <li><a href="products.html">Products</a></li>
      <li><a href="about_us.html">About Us</a></li>
      <li><a href="contact_us.html">Contact Us</a></li>
    </ul>
    <p>  </p>
    <div id="apDiv"><span class="content"><img src="images/newsletter_example.png" width="211" height="739" /></span></div>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <div id="apDiv2"><img src="images/sign_up_reward.png" width="500" height="327" /></div>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p><!-- end .sidebar1 --></p>
  </div>
  <div class="content">
    <blockquote>
      <form id="form1" name="form1" method="post" action="contactformprocess.php">
        <table width="100%" border="1" cellpadding="6">
          <tr>
            <td width="23%" align="right"><label for="first_name6">First Name:</label></td>
            <td width="77%" align="left"><input name="fname" type="text" id="first_name6" size="25" /></td>
          </tr>
          <tr>
            <td align="right"><label for="lname">Last Name:</label></td>
            <td align="left"><input name="lname" type="text" id="lname" value="" size="25" /></td>
          </tr>
          <tr>
            <td height="39" align="right"><label for="email">Email:</label></td>
            <td align="left"><input name="email" type="text" id="email" size="50" maxlength="90" /></td>
          </tr>
          <tr>
            <td height="39" align="right"> </td>
            <td align="left"><input type="submit" name="submit" id="submit" value="Submit Information" /></td>
          </tr>
        </table>
      </form>
    </blockquote>
<!-- end .content --></div>
  <div class="footer">
    <p>If you have any questions, please feel free to call us at 770-944-0796 or toll-free 1-866-944-0796.</p>
  <!-- end .footer --></div>
<!-- end .container --></div>
</body>
</html>
Link to comment
Share on other sites

Was just looking at the form again and does the highlighted part have it all screwed up>? 

 

<form id="form1" name="form1" method="post" action="contactformprocess.php">

        <table width="100%" border="1" cellpadding="6">

          <tr>

            <td width="23%" align="right"><label for="first_name6">First Name:</label></td>

            <td width="77%" align="left"><input name="fname" type="text" id="first_name6" size="25" /></td>

          </tr>

          <tr>

            <td align="right"><label for="lname">Last Name:</label></td>

            <td align="left"><input name="lname" type="text" id="lname" value="" size="25" /></td>

          </tr>

          <tr>

            <td height="39" align="right"><label for="email">Email:</label></td>

            <td align="left"><input name="email" type="text" id="email" size="50" maxlength="90" /></td>

          </tr>

          <tr>

            <td height="39" align="right"> </td>

            <td align="left"><input type="submit" name="submit" id="submit" value="Submit Information" /></td>

          </tr>

        </table>

      </form>

Link to comment
Share on other sites

No, the highlighted part is correct. PHP doesn't care or even know about the input's ID; it only cares about the name.

 

Try sending complete HTML.

$body = <<<EOD
<!DOCTYPE html>
<html>
<head></head>
<body>
<br><hr><br>
First Name: $fname <br>
Last Name: $lname <br>
Email: $email <br>
</body>
</html>
EOD;
Link to comment
Share on other sites

Oh ok, thank you so much for taking the time to help me.  :happy-04:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aftermarket home page</title>
<style type="text/css">
<!--
body {
	font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
	background-color: #660000;
	margin: 0;
	padding: 0;
	color: #FFF;
	background-image: url(images/Untitled-1.png);
}

/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
	padding: 0;
	margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
	margin-top: 0;	 /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
	padding-right: 15px;
	padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
	animation-play-state: running;
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
	border: none;
}

/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
	color: #FFFFFF;
	text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:visited {
	color: #FFFFFF;
	text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
	text-decoration: none;
}

/* ~~this fixed width container surrounds the other divs~~ */
.container {
	width: 960px;
	background-color: #333;
	margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
	background-image: url(images/carbon_fiber.png);
}

/* ~~ the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo ~~ */
.header {
	background-color: #ADB96E;
}

/* ~~ These are the columns for the layout. ~~ 

1) Padding is only placed on the top and/or bottom of the divs. The elements within these divs have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.

2) No margin has been given to the columns since they are all floated. If you must add margin, avoid placing it on the side you're floating toward (for example: a right margin on a div set to float right). Many times, padding can be used instead. For divs where this rule must be broken, you should add a "display:inline" declaration to the div's rule to tame a bug where some versions of Internet Explorer double the margin.

3) Since classes can be used multiple times in a document (and an element can also have multiple classes applied), the columns have been assigned class names instead of IDs. For example, two sidebar divs could be stacked if necessary. These can very easily be changed to IDs if that's your preference, as long as you'll only be using them once per document.

4) If you prefer your nav on the right instead of the left, simply float these columns the opposite direction (all right instead of all left) and they'll render in reverse order. There's no need to move the divs around in the HTML source.

*/
.sidebar1 {
	float: left;
	width: 180px;
	background-color: #000000;
	padding-bottom: 10px;
	background-image: url(images/red-textures_00273047.jpg);
	position: relative;
}
.content {

	padding: 10px 0;
	width: 780px;
	float: left;
}

/* ~~ This grouped selector gives the lists in the .content area space ~~ */
.content ul, .content ol { 
	padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */
}

/* ~~ The navigation list styles (can be removed if you choose to use a premade flyout menu like Spry) ~~ */
ul.nav {
	list-style: none; /* this removes the list marker */
	border-top: 1px solid #666; /* this creates the top border for the links - all others are placed using a bottom border on the LI */
	margin-bottom: 15px; /* this creates the space between the navigation on the content below */
}
ul.nav li {
	border-bottom: 1px solid #666; /* this creates the button separation */
}
ul.nav a, ul.nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */
	padding: 5px 5px 5px 15px;
	display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
	width: 160px;  /*this width makes the entire button clickable for IE6. If you don't need to support IE6, it can be removed. Calculate the proper width by subtracting the padding on this link from the width of your sidebar container. */
	text-decoration: none;
	background-color: #00FF00;
	background-image: url(images/red-textures_00273047.jpg);
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */
	background-color: #990000;
	color: #999;
}

/* ~~ The footer ~~ */
.footer {
	padding: 10px 0;
	background-color: #CCC49F;
	position: relative;/* this gives IE6 hasLayout to properly clear */
	clear: both; /* this clear property forces the .container to understand where the columns end and contain them */
	background-image: url(images/red-textures_00273047.jpg);
}

/* ~~ miscellaneous float/clear classes ~~ */
.fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
	float: right;
	margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
	float: left;
	margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
	clear:both;
	height:0;
	font-size: 1px;
	line-height: 0px;
}
#apDiv1 {
	position: absolute;
	width: 185px;
	height: 75px;
	z-index: 1;
	left: 4px;
	top: 128px;
}
#apDiv2 {
	position: absolute;
	width: 200px;
	height: 115px;
	z-index: 1;
	left: 218px;
	top: 232px;
}
#apDiv3 {
	position: absolute;
	width: 214px;
	height: 111px;
	z-index: 2;
	left: 638px;
	top: 458px;
}
#apDiv4 {
	position: absolute;
	width: 205px;
	height: 67px;
	z-index: 1;
	left: -1px;
	top: -71px;
}
#apDiv5 {
	position: absolute;
	width: 502px;
	height: 334px;
	z-index: 2;
	left: 438px;
	top: 364px;
}
#apDiv {
	position: absolute;
	width: 375px;
	height: 673px;
	z-index: 2;
	left: 741px;
	top: 223px;
}
-->
</style></head>

<body>

<div class="container">
  <div class="header"><!-- end .header --><a href="index.html"><img src="AAP Header.png" alt="Insert Logo Here" name="Insert_logo" width="960" height="175" id="Insert_logo" style="background-color: #FFFFFF; display: block;" /></a></div>
  <div class="sidebar1">
    <ul class="nav">
      <li><a href="why_buy_from_us.html">Why buy from us?</a></li>
      <li><a href="products.html">Products</a></li>
      <li><a href="about_us.html">About Us</a></li>
      <li><a href="contact_us.html">Contact Us</a></li>
    </ul>
    <p>  </p>
    <div id="apDiv"><span class="content"><img src="images/newsletter_example.png" width="211" height="739" /></span></div>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <div id="apDiv2"><img src="images/sign_up_reward.png" width="500" height="327" /></div>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p><!-- end .sidebar1 --></p>
  </div>
  <div class="content">
     <blockquote>
      <form id="form1" name="form1" method="post" action="contactformprocess.php">
        <table width="100%" border="1" cellpadding="6">
          <tr>
            <td width="23%" align="right"><label for="first_name6">First Name:</label></td>
            <td width="77%" align="left"><input name="fname" type="text" id="first_name6" size="25" /></td>
          </tr>
          <tr>
            <td align="right"><label for="lname">Last Name:</label></td>
            <td align="left"><input name="lname" type="text" id="lname" value="" size="25" /></td>
          </tr>
          <tr>
            <td height="39" align="right"><label for="email">Email:</label></td>
            <td align="left"><input name="email" type="text" id="email" size="50" maxlength="90" /></td>
          </tr>
          <tr>
            <td height="39" align="right"> </td>
            <td align="left"><input type="submit" name="submit" id="submit" value="Submit Information" /></td>
          </tr>
        </table>
      </form>
    </blockquote>
<!-- end .content --></div>
  <div class="footer">
    <p>If you have any questions, please feel free to call us at 770-944-0796 or toll-free 1-866-944-0796.</p>
  <!-- end .footer --></div>
<!-- end .container --></div>
</body>
</html>

Link to comment
Share on other sites

Ok, so I got it where it's emailing me again, and put in your code instead to send the whole thing. But still a blank form. It gives me a subject on the email i receive but no "from" and when I open it, it says

 

First Name:

Last Name:

Email:

Link to comment
Share on other sites

Did you put the error code at the top like I suggested? Are you getting any errors?

 

Your code should work, if those variables have data in them. Can you view the source of the email to see if there is something weird going on where the values are supposed to be?

Link to comment
Share on other sites

This is the working code, It still doesn't have the "from" person on the email. But when I open it, it has all the info I need.

<?php

/* Subject and Email Variables*/

	$emailSubject = 'Contact Info!';
	$webMaster = 'AAPemails@gmail.com';
	
/*Gathering Data Variables*/
	
	$fnameField = $_POST['fname'];
	$lnameField = $_POST['lname'];
	$emailField = $_POST['email'];
	
	$body =	<<<EOD
<br><hr><br>
First Name: $fnameField <br>
Last Name: $lnameField <br>
Email: $emailField<br>
EOD;


	$headers = "From: $email\r\n";
	$headers .= "Content-type: text/html\r\n";
	$success = mail($webMaster, $emailSubject, $body, $headers);
	
/*Results rendered as HTML */


	
	$theResults = <<<EOD

<html>
<head>
<title>AAP Newsletter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
	background-color: #f1f1f1;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-style: normal;
	line-height: normal;
	font-weight: normal;
	color: #666666;
	text-decoration: none;
	
-->
</style>
</head>

<div>
	<div align="left">Thank you for your time. You will recieve an email soon.</div>
</div?
</body>
</html>
EOD;
echo "$theResults";

?>

Link to comment
Share on other sites

You should be developing with error reporting on, and you would have seen something like this. Put this at the top of your script before anything else:

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

 

I'd recommend you turn them on globally in your php.ini though. Search your php.ini for "display_errors" and "error_reporting" and set them to the same values as above, and then restart Apache.

Link to comment
Share on other sites

So, by putting that at the top of my page before I start scripting it will automatically flag anything that's not working? Again sorry I'm a complete noob when it comes to coding.

 

If you wanted to see where all this was going the website is www.aftermarketap.com coded the whole thing myself. I don't think its too bad for my first website.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.