Jump to content

Form fails to email


Shamrox

Recommended Posts

Can anyone make rhyme or reason out of why I always get a failure output instead of the form emailing? Other forms using the same code work, but the invoice fails.

 

?php

if(@$_REQUEST['step'] != "two")
{
ob_start();
	include("invoice.php");
	$to = $invoice['billemail']; //change this
ob_end_clean();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Send <?PHP echo $_REQUEST['form']; ?></title>
</head>
<body>
<form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="invoicenumber" value="<?PHP echo $_REQUEST['invoicenumber']; ?>">
<input type="hidden" name="form" value="<?PHP echo $_REQUEST['form']; ?>">
<input type="hidden" name="step" value="two">
<p>
Send <?PHP echo $_REQUEST['form']; ?> to: <input type="text" name="send_to" value="<?PHP echo $to; ?>" size="50"> (Example: [email protected], [email protected])<br>
<input type="submit" name="submit_button" value="Send <?PHP echo $_REQUEST['form']; ?>">
</p>
</form>
</body>
</html>
<?PHP
exit();
}elseif(@$_REQUEST['step'] == "two"){
	ob_start();
	if($_REQUEST['form'] == "invoice"){
	include("invoice.php");
 }

	$message = ob_get_contents();
	ob_end_clean();
	$success = "Invoice sent successfully.";
	$failure = "Failed to send invoice email!!";
	if($_REQUEST['form'] == "invoice"){
	$success = "Invoice sent successfully.";
	$failure = "Failed to send invoice email.";
	$from = $invoice['stb_email'];
	$subject = "Invoice - " . $invoice['invoicenumber'] . " - " . $invoice['studentlast'] . " - " . $invoice['coursecode'] . " - " . $invoice['coursename'] . "";
	}else	{
	$send_to = $_POST['send_to'];
	$message = str_replace("../invoice.css", "http://www.domain.com/invoice.css", $message);
	$message = preg_replace("/\.?\.?\/images\/logo_hi-res_sm.gif/", "http://www.domain.com/images/logo_hi-res_sm.gif", $message);
	$message = str_replace("/images/gray_dot.gif", "http://www.domain.com/images/gray_dot.gif", $message);
	$message = str_replace("/images/shared_dot_clear.gif", "http://www.domain.com/images/shared_dot_clear.gif", $message);

	$sep = "\n";
	$boundary = md5(uniqid("",true));
	$b1 = "b1---$boundary";
	$headers  = "From: $from$sep";
	$headers .= "Return-Path: $from$sep";
	$headers .= "MIME-Version: 1.0$sep";
	$headers .= "Content-Type: multipart/alternative; boundary=\"$b1\"$sep";
	$headers .= "$sep";  

	//now set up the message
	$messageHeader = "--$b1$sep";
	//default message
	$defaultmessage = "Your email client cannot read html email";
	$messageHeader .= $defaultmessage.$sep;
	$messageHeader .= "$sep";  
	//html message
	$messageHeader .= "--$b1$sep";
	$messageHeader .= 'Content-Type: text/html; charset="iso-8859-1"'.$sep;
	$messageHeader .= "Content-Transfer-Encoding: 8bit$sep";
	$messageHeader .= "$sep";
	$messageHeader .= $message;
	$messageHeader .= "$sep";
	$messageHeader .= "--$b1--";
	$messageHeader .= "$sep";

	echo "<pre>$headers \r\n $messageHeader</pre>";

	$results = @mail($send_to, $subject, $messageHeader, $headers);
}if($results){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Message Sent</title>
</head>
<body>
<p><a href="dashboard-new.php">Dashboard</a> | <a href="registrar_new.php?registrarid=<?PHP echo $_REQUEST['registrarid']; ?>">Registrar</a></p>
<p><?PHP echo $success; ?></p>
<p>Message sent to: <?PHP echo $send_to; ?></p>
<p>The following message was sent:</p>
<hr>
<?PHP echo $message; ?>
</body>
</html>
<?PHP
}else	{
	echo $failure;
}	
exit();
}
?>

Link to comment
https://forums.phpfreaks.com/topic/53786-form-fails-to-email/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.