Jump to content

PHP Mail Not Sending Results


newseed

Recommended Posts

I inherited a site that has a php email script embedded into a WP site. This seems to be a non-WP script. The issue is that the client receives a email notification when someone submits an email but the notification email comes blank.

 

 

<form action="http://www.SITEURL.com/fb-html/mail.php" onsubmit="javascript:return validForm(document.mailinglist)" name="mailinglist" id="mailinglist"><input  name="email" id="email"type="text" onblur="if (this.value == '') {this.value = 'Enter email address...';}" onfocus="if (this.value == 'Enter email address...') {this.value = '';}" size="20" value="Enter email address..."><input type="image" class="button-ok" src="http://SITEURL.com/wp-content/themes/twentyten/images/mailing-button-ok.gif"></form>

Here's the form action code (mail.php):

 

 

 

<?php/* Set e-mail recipient info@SITEURL.com*/$myemail  = "info@SITEURL.com";$subject  = "Join Our Mailing List";$headers = "From: SITE NAME Peace Movement <info@SITEURL.com>rn";$from = "SITE NAME Peace Movement <info@SITEURL.com>";/* Check all form inputs using check_input function *//* Let's prepare the message for the e-mail */$message = "Site name: SITE NAMEYour Mailing List form has been submitted by:Email: $email";/* Send the message using mail() function */mail($myemail, $subject, $message, $headers);        $myemail1=$_REQUEST['email'];        $subject="We're in this together!";        $headers = "From: SITE NAME Peace Movement <info@SITEURL.com>rn";//$headers = "From: SITE NAME <info@SITEURL.com>rn";        $from ="SITE NAME <info@SITEURL.com>";        $message = "<table width='100%' border='0' cellspacing='0' cellpadding='0' style='background:#183e69; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333; padding:0px; margin:0px;' height='100%'><tr>    <td align='center' valign='top'> </td></tr>  <tr>    <td align='center' valign='top'>    <table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='background:#fff;' >  <tr>    <td align='center' valign='top' style='padding:15px 0;'><a href='http://www.SITEURL.com/' target='_blank'><img src='http://www.SITEURL.com/fb-html/the-universal-flag-logo.jpg' alt='THE SITE NAME' width='433' height='98' border='0'></a></td>  </tr>  <tr>    <td align='center' valign='top'><img src='http://www.SITEURL.com/fb-html/banner-img.jpg' width='568' height='267' alt='banner'></td>  </tr>  <tr>    <td align='center' valign='top'> </td>  </tr>  <tr>    <td align='left' valign='top'><table width='95%' border='0' align='center' cellpadding='0' cellspacing='0'>      <tr>        <td align='left' width='100%' valign='top'>          <p style='padding:0px; margin:0px; line-height:20px; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#333;  text-align: left;'>            Dear Friend,<br>            <img src='http://www.SITEURL.com/fb-html/universal-flag.jpg' width='164' height='164' align='right' alt='SITE NAME' style='float:right; margin:10px 0px 10px 15px;' />  <br>            Welcome to the SITE NAME Peace Movement! We are a 501c3 non-profit collective, comprised of students, authors, environmentalists, musicians, artists, spiritual leaders, activists, mothers, fathers, and every day people...just like youfrom around the globe. Together, we are working to bring about peace by reminding others...we are all connected.<br>  <br>            Want to get more involved in the SITE NAME Peace Movement?<br>  <br>            Please consider the following:<br>  <br>                       </p>          <table width='100%' border='0' cellspacing='0' cellpadding='0'>            <tr>             <td width='95%' align='left' valign='middle' style='font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#333;'>-      Like us on Facebook by visiting our page <a href='http://www.facebook.com/SITEURL' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#0e7791; text-decoration: underline;' target='_blank'>here</a> - and suggest our page to your friends!</td>              </tr>            <tr>              <td align='center' valign='top'> </td>              <td align='left' valign='middle'> </td>            </tr>                                   <td width='95%' align='left' valign='middle' style='font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#333;'>-      Follow us on Twitter by visiting our <a href='http://www.twitter.com/universal_flag' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#0e7791; text-decoration: underline;' target='_blank'>Twitter</a> page</td>              </tr>            <tr>              <td align='center' valign='top'> </td>              <td align='left' valign='middle'> </td>              </tr>            <tr>                         <td width='95%' align='left' valign='middle' style='font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#333;'>-                      Purchase a flag from our <a href='http://store.SITEURL.com' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#0e7791; text-decoration: underline;' target='_blank'>online store</a> and share it with your friends, family, and community                </td>              </tr>            <tr>              <td align='center' valign='top'> </td>              <td align='left' valign='middle'> </td>              </tr>            <tr>                         <td width='95%' align='left' valign='middle' style='font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#333;'>-                      Write us at <a href='mailto:info@SITEURL.com' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#0e7791; text-decoration: underline;'>info@SITEURL.com</a> to volunteer - we have lots of opportunities for people in every country! </td>              </tr>            <tr>              <td align='center' valign='top'> </td>              <td align='left' valign='middle'> </td>              </tr>            <tr>                           <td width='95%' align='left' valign='middle' style='font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#333;'>-                      Become an affiliate and sell SITE NAMEs to earn money for your own organization - write <a href='mailto:info@SITEURL.com'  style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#0e7791; text-decoration: underline;'>info@SITEURL.com</a> for more info. </td>              </tr>            <tr>              <td align='center' valign='top'> </td>              <td align='left' valign='middle'> </td>              </tr>            </table>          <p style='padding:0px; margin:0px; line-height:20px; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#333; text-align:left;'>            You'll be receiving periodic updates, invitations, and announcements about special deals and giveaway contests. We will never sell, rent or give your name or email address to anyone. And, you can always unsubscribe by clicking the link at the bottom of any future emails.<br>  <br>            Thanks again for registering. If you have any questions or comments, feel free to contact us.<br>  <br>  <br>  <strong>Namaste,<br>    Brian McClure & the SITE NAME community</strong><br>  <br>  <br>            P.S. If you are not familiar with the meaning of the flag and symbol, you can find it <a href='http://www.SITEURL.com/about/' target='_blank' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#0e7791; text-decoration: underline;'>here</a></p>          </td>        </tr>           <tr>        <td align='left' valign='top'> </td>        </tr>      <tr>        <td align='left' valign='top'><img src='http://www.SITEURL.com/fb-html/heading-line-img.jpg' width='562' height='25' alt='heading'></td>        </tr>      <tr>        <td align='left' valign='top'> </td>        </tr>      <tr>        <td align='left' valign='top'><table width='100%' border='0' cellspacing='0' cellpadding='0'>          <tr>            <td width='38%' align='left' valign='middle'><a href='http://www.facebook.com/SITEURL' target='_blank'><img src='http://www.SITEURL.com/fb-html/facebook-img.jpg' alt='Facebook' width='137' height='42' border='0'></a></td>            <td width='40%' align='left' valign='middle'><a href='http://twitter.com/Universal_Flag' target='_blank'><img src='http://www.SITEURL.com/fb-html/twitter-img.jpg' alt='Twitter' width='143' height='42' border='0'></a></td>            <td width='22%' align='left' valign='middle'><a href='http://www.youtube.com/user/3SITEURL3' target='_blank'><img src='http://www.SITEURL.com/fb-html/youtube-img.jpg' alt='Youtube' width='97' height='42' border='0'></a></td>            </tr>          </table></td>        </tr>      <tr>        <td align='left' valign='top'> </td>        </tr>      </table></td>  </tr>  </table>       </td>  </tr>  <tr>    <td align='center' valign='top'> </td>  </tr>  <tr>    <td align='center' valign='top' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#fff;'>©2012 SITE NAME Companies. All Rights Reserved</td>  </tr>  <tr>    <td align='center' valign='top'> </td>  </tr></table>";$headers  = "MIME-Version: 1.0n";                $headers .= "Content-type: text/html; charset=iso-8859-1n";                $headers .= "X-Priority: 3n";                $headers .= "X-MSMail-Priority: Normaln";                $headers .= "X-Mailer: phpn";                $headers .= 'From: SITE NAME Peace Movement <info@SITEURL.com>'. "rn";                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";               mail($myemail1, $subject, $message, $headers);/* Redirect visitor to the thank you page */header('Location: http://www.SITEURL.com');exit();//------------------------------------------------------------------------------------------function formSelected( $var, $val ){    echo ( $var == $val ) ? "selected" : "";}//------------------------------------------------------------------------------------------function formChecked( $var, $val ){    echo ( $var == $val ) ? "checked" : "";}/* Functions we used */function check_input($data, $problem=''){    $data = trim($data);    $data = stripslashes($data);    $data = htmlspecialchars($data);    if ($problem && strlen($data) == 0)    {        show_error($problem);    }    return $data;}function checkbox_values($checkbox_array) {  $s = "";  foreach ($checkbox_array as $c) {     $s = $s . " " . $c;   }  return $s;}function show_error($myError){?>    <html>    <body>    <b>Please correct the following error:</b><br />    <?php echo $myError; ?>    </body>    </html><?phpexit();}?>

Any help would be greatly appreciated.

Link to comment
Share on other sites

That's some pretty awful-looking PHP code.

 

There's this part at the top:

 

 

$myemail= "info@SITEURL.com";$subject  = "Join Our Mailing List";$headers ="From: SITE NAME Peace Movement<info@SITEURL.com>rn";$from= "SITE NAME Peace Movement <info@SITEURL.com>";/* Check all form inputs usingcheck_input function *//* Let's prepare themessage for the e-mail */$message = "Site name: SITENAMEYour Mailing List form has been submitted by:Email:$email";/* Send themessage using mail() function */mail($myemail, $subject, $message, $headers);

 

So that's going to send an email with that subject and message. The $message variable is trying to use a variable called $email, but it hasn't been defined anywhere, so that's going to be blank.

 

Then it has this code:

 

 

$myemail1=$_REQUEST['email'];        $subject="We're in this together!";        $headers= "From: SITE NAME Peace Movement<info@SITEURL.com>rn";//$headers = "From: SITE NAME<info@SITEURL.com>rn";       $from ="SITE NAME<info@SITEURL.com>";

 

So it actually gets the email value from the form, and saves it in $myemail1, and then builds another subject line and list of headers. There's a syntax error there though, which you can see by the messed up highlighting before the $from line. Then there's that chunk of HTML that it puts into the $message variable, and after that it overwrites the $header variable with this:

 

 

$headers  ="MIME-Version: 1.0n";               $headers .="Content-type: text/html;charset=iso-8859-1n";                $headers.= "X-Priority: 3n";               $headers .= "X-MSMail-Priority: Normaln";               $headers .="X-Mailer: phpn";               $headers .='From: SITE NAME Peace Movement<info@SITEURL.com>'."rn";               $headers .= 'Content-type: text/html;charset=iso-8859-1' . "rn";

 

One problem there is that some of the headers are separated with just n, and they need to be separated with rn. It looks like there is a line break in the middle of the content-type header, that's going to be a problem also. The From header also has a line break in the middle of it. Then there's another content-type header, which also has a line break in it.

Link to comment
Share on other sites

Thanks for the reply. So it seems that this form is poorly coded or outdated. Can you suggest a simply php form to collect a single email and have it sent to the recipient? PHP is not my strong point and so I am open for suggestion to either fix this one or try another.

 

Thanks again.

Link to comment
Share on other sites

There's a basic form example here which includes email validation also, which is another thing that code lacks. Someone could use that form to send any email message to any address, so the example here corrects for that by validating the email address that is entered:

 

http://www.w3schools.com/php/php_secure_mail.asp

Link to comment
Share on other sites

I am totally oblivious that I cannot get a simple email form to send a one line field collecting a email address only.

 

Somebody please help me get it working. I tried using the one for W3C (link in this topic) with no success.

 

I just need a simple email collector with a secure way to prevent injections to the form.

Link to comment
Share on other sites

The form is the same as the one in the W3C link but not sending the results to the recipient. I mean it sends the results but to an recipient email but the email field entered does not get sent.

Edited by newseed
Link to comment
Share on other sites

You can change the email text to be whatever you want. The example uses a text box for the email message, and they just get that from the form and use it as the body. You can change the form and build the body text however you want, it's just a string of text. Put whatever text you want into the body, include whatever other information from the form you want to go in there, etc. The manual describes how to work with strings if you're not familiar:

 

http://php.net/manual/en/language.types.string.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...