Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php emailer

Status
Not open for further replies.

lakeside12

Programmer
Apr 20, 2009
43
CA
Hi
Below is the standard mail.php from a php mailer

Can you tell me why the SUBJECT fails to show up in the autoresponse e-mail that is set out. Instead I get the body of the mail sent in the subject

In the calling program I have the following

Code:
<input name="recipient" type="hidden" value="my@mail.com" /> 
<input name="subject" type="hidden" value="test sub " />
<input name="required" type="hidden" value="email" />
<input name="errorpage" type="hidden" value="errorpage.html" />
<input name="redirect" type="hidden" value="ThankYou.php" />
<input name="autoresponse" type="hidden" value="autoresponse.html" />
<input name="mailsubject" type="hidden" value="test subject" />
<input name="autoresponsefrom" type="hidden" value="the test name" />

In the main mail program mail.php

Code:
<?php
if ($_POST[recipient] && $_POST[subject] && $_POST[redirect]) {
  
  if ($_POST[required]) {
    $rfields = explode (",",$_POST[required]);
	foreach ($rfields as $check) {
	  if (!$_POST[$check]) {
	    header("Location: ".$_POST[errorpage]);
		exit(); 
	  }
	} 
  }
  
  if ($_POST[autoresponse] && $_POST[email]) {
    $html = file_get_contents($_POST[autoresponse]) or die("<b><font color=\"#ff0000\">Not a valid autoresponse page...</font><b>");
	if ($html) {
	  $tit_start = strpos($html,"<title>")+7;
	  $tit_end = strpos($html,"</title>")-$tit_start;
	  $mailsubject = $html;
	  $mailsubject = substr($mailsubject, $tit_start, $tit_end);
	  mail($_POST[email], $mailsubject, $html, "From: $_POST[autoresponsefrom]<$_POST[recipient]>\r\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=iso-8859-1");
	}
  }
  else if (!$_POST[email]) {
    echo "<b><font color=\"#ff0000\">Email field required when using autoresponse mail...</font></b>";
    exit();
  }
  
  $ndata = array("recipient","subject","required","errorpage","redirect","autoresponse","autoresponsefrom");
  
  $postfields = $_REQUEST;
  
  foreach ($postfields as $k => $v) {
    if (in_array($k,$ndata)) unset($postfields[$k]);
	else $msg .= $k.": ".$v."\n";
  }
  
  mail($_POST[recipient],$_POST[subject],$msg,"From: $_POST[email]\r\n"."Reply-To: $_POST[email]\r\n");
  header("Location: ".$_POST[redirect]);



}
else echo "<b><font color=\"#ff0000\">Recipient, subject or redirect field is missing...</font></b>";



?>
 
Because you are sending your autoresponse page in the subject:

Code:
 if ($_POST[autoresponse] && $_POST[email]) {
    [red]$html[/red] = file_get_contents($_POST[autoresponse]) or die("<b><font color=\"#ff0000\">Not a valid autoresponse page...</font><b>");
    if ($html) {
      $tit_start = strpos($html,"<title>")+7;
      $tit_end = strpos($html,"</title>")-$tit_start;
[red]      $mailsubject = $html;[/red]
      $mailsubject = substr($mailsubject, $tit_start, $tit_end);
      mail($_POST[email], [red]$mailsubject[/red], $html, "From: $_POST[autoresponsefrom]<$_POST[recipient]>\r\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=iso-8859-1");
    }


I'm guessing that $mailsubject variable should be equal to something other than the HTML from the response page file.

Additionally you should be getting tons of Notices in your logs that certain constants are not defined. All array keys should always be quoted unless the variable is inside an already enquoted string.

Code:
So $_POST[xxxxx]  should be $_POST[[COLOR=white red]'[/color]xxxxx[COLOR=white red]'[/color]]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top