Trouble with PHP Mailing Script

Hello,

I am experiencing some trouble with the following php mail script not sure if im doing something wrong.

[php] <?php
ini_set(‘display_errors’,1);

ini_set(“SMTP”,“ssl://mail.shaw.ca”);
ini_set(“smtp_port”,“587”);
ini_set(“username”,"");
ini_set(“password”,"********");
ini_set(“sendmail_from”,“[email protected]”);

$to_email = “[email protected]”;

$subject = “Registration Request from Website”;
$fields = $_REQUEST;
//foreach($fields as $key => $value) {
// echo “$key = $value
”;
//}
if($fields[eadd] !== “”) {$from_email = $fields[eadd];} else {$from_email = “[email protected]”;}

$ip = $_SERVER[‘REMOTE_ADDR’];
$time = date(‘r’);
$body = <<<EOD

Online Event Registration Request… Please Contact:

Name: $fields[name]
Phone: $fields[phone]
Email: $fields[eadd]
Club Name & Number: $fields[clubname]
City/Town: $fields[town]
Province: $fields[province]
Perferred Shoot Time: $fields[shoottime]
Class: $fields[cl]
Event: $fields[event]
Other Info: $fields[other]

Sent: $time
senders ip:$ip

EOD;
mail($to_email, $subject, $body, “From: $from_email\r\nReply-To: $from_email\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nMIME-Version: 1.0”);
?>

Stavely Archery Lanes Event Registration .style2 { font-family: Arial, Helvetica, sans-serif; font-size: large; color: #FFFFFF; } .style3 { color: #FFFFFF; } Thank You!
We will be in contact with you soon

[/php]

I have it showing errors for right now below is the error output:

Notice: Use of undefined constant eadd - assumed ‘eadd’ in /var/www/clients/client5/web37/web/mail_script.php on line 18

Any help would be huge!

Looks like you have a contact form that calls this mail script, on that contact form I bet you’re missing an input boxed named eadd.

If you post the code to the contact form, it’ll be easier to point you in the right direction.

<head>
<title>Stavely Archery Lanes Event Registration</title>
<base target="_blank">
<style type="text/css">
.style1 {
	text-align: center;
	color: #FFFFFF;
	font-family: Arial, Helvetica, sans-serif;
}
.style2 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: x-large;
	color: #FFFFFF;
}
</style>
</head>

<body style="background-color: #2F650D">


<center class="style2"><strong>Stavely Archery Lanes Event Registration<br>
</strong></center>

<p></p>

<form id="form1" method="post" action="mail_script.php" onSubmit="window.close();">
	<div class="style1" id="class">
		<p><strong>Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>&nbsp;
		<input name="name" type="text" style="width: 230px"><br>
		<br>
		<strong>E-mail Address:</strong>&nbsp;
		<input name="eadd" type="text" style="width: 230px"><br>
		<br>
		<strong>Club Name &amp; #</strong>&nbsp;&nbsp;&nbsp;&nbsp;
	  <input name="clubname" type="text" style="width: 230px"><br>
		<strong><br>
		City/Town:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>&nbsp;
		<input name="town" type="text" style="width: 230px"><br>
		<br>
		<strong>Province:&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		</strong>&nbsp;
		<input name="province" type="text" style="width: 230px"><br>
		<br>
		<strong>Postal Code:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>&nbsp;
		<input name="postalcode" type="text" style="width: 230px"><br>
		<br>
		<strong>Phone Number: </strong>&nbsp;
		<input name="phone" type="text" style="width: 230px"><br>
		<br>
		<strong>Shoot Time:&nbsp; 
		<select name="shoottime" size="1">
		  <option>9:00 AM</option>
		  <option>10:15 AM</option>
		  <option>11:30 AM</option>
		  <option>9:00 AM or 11:30 AM or 10:15 AM</option>
	    </select>
		<br>
		<br>
		Class 
		<select name="cl" size="1">
		  <option selected="">M60 Male</option>
		  <option>M60 Female</option>
		  <option>M50 Male</option>
		  <option>M50 Female</option>
		  <option>BHO Male</option>
		  <option>BHO Female</option>
		  <option>BHR Male</option>
		  <option>BHR Female</option>
		  <option>BHF Male</option>
		  <option>BHF Female</option>
		  <option>JRC Male</option>
		  <option>JRC Female</option>
		  <option>CADC Male</option>
		  <option>CADC Female</option>
		  <option>HUN Male</option>
		  <option>HUN Female</option>
		  <option>HF Male</option>
		  <option>HF Female</option>
		  <option>M50TR Male</option>
		  <option>M50TR Female</option>
		  <option>BB Male</option>
		  <option>BB Female</option>
		  <option>TRD Male</option>
		  <option>TRD Female</option>
		  <option>IN Male</option>
		  <option>IN Female</option>
		  <option>JRT Male</option>
		  <option>JRT Female</option>
		  <option>CADT Male</option>
		  <option>CADT Female</option>
		  <option>CUBT Male</option>
		  <option>CUBT Female</option>
		  <option>PCUBT Male</option>
		  <option>PCUBT Female</option>
		  <option>CUBC Male</option>
		  <option>CUBC Female</option>
		  <option>PCUBC Male</option>
		  <option>PCUBC Female</option>
	    </select>
		<br>
		<br>
		Event: 
		<select name="event" size="1">
		  <option>Stavely Archery Lanes Doug Symonds 3D Memorial Shoot</option>
		  <option>Stavely Archery Lanes Annual 3D Indoor Tournament March 15th 2014</option>
		  <option>Stavely Archery Lanes 3D Outdoor Spring Shoot May 17th,18th,19th 2014</option>
	    </select>
		<br>
		<br>
		Other Information:<br>
		<br>
		<input name="other" type="text" style="width: 340; height: 35" size="100" tabindex="100"><br>
&nbsp;<br>
		</strong>
		<input name="submitform" type="submit" value="submit">&nbsp;&nbsp;&nbsp;&nbsp;
		<input name="Reset1" type="reset" value="reset">
		</p>
		<p><br>
		  <br>
	  </p>
    </div>
</form>






</body>

</html>

Here it is sorry i should have posted it as well thanks a million!

Try changing…

[php]if($fields[eadd] !== “”) {$from_email = $fields[eadd];} else {$from_email = “[email protected]”;}[/php]

to:

[php]if($fields[‘eadd’] !== “”) {$from_email = $fields[‘eadd’];} else {$from_email = “[email protected]”;}[/php]

That fixed the error! But i am still not receiving the physical e-mail which has me confused

I have now moved to using Pear Mailing rather than just php mail i cannot see where Ive gone wrong it doesnt send any e-mails.

PHP Script:

[php]<?php

if(isset($_POST[‘eadd’])) {
require_once “PEAR/Mail.php”;

$email_to = "[email protected]";
$email_subject = “Registration Request”;
$host = “184.70.113.194”;
$username = "[email protected]";
$from_address = "[email protected]";
$password = “*******”;
$reply_to = "[email protected]";
$port = “587”;

function died($error) {
// your error code can go here
echo “We are very sorry, but there were error(s) found with the form you submitted. “;
echo “These errors appear below.

”;
echo $error.”

”;
echo “Please go back and fix these errors.

”;
die();
}

// Validate expected data exists
if(!isset($_POST[‘name’]) || !isset($_POST[‘eadd’]) || !isset($_POST[‘club_name’]) || !isset($_POST[‘province’]) || !isset($_POST[‘comments’])) {
died(‘We are sorry, but there appears to be a problem with the form you submitted.’);
}

$name = $_POST[‘name’]; // required
$eadd = $_POST[‘eadd’]; // required
$club_name = $_POST[‘club_name’]; // not required
$town = $_POST[‘town’]; // required
$province = $_POST[‘province’]; // not required
$pcode = $_POST[‘pcode’]; // not required
$phone = $_POST[‘phone’]; // not required
$shoottime = $_POST[‘shoottime’]; // not required
$class = $_POST[‘class’]; // not required
$event = $_POST[‘event’]; // not required
$comments = $POST[‘comments’]; // required
$error_message = “”;
$email_exp = '/^[A-Za-z0-9.
%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/’;
if(!preg_match($email_exp,$eadd)) {
$error_message .= ‘The Email Address you entered does not appear to be valid.
’;
}
$string_exp = “/^[A-Za-z .’-]+$/”;
if(!preg_match($string_exp,$name)) {
$error_message .= ‘The Name you entered does not appear to be valid.
’;
}
if(strlen($comments) < 1)
$error_message .= ‘The Comments you entered do not appear to be valid.
’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Registraion details below.\n\n”;
function clean_string($string) {
$bad = array(“content-type”,“bcc:”,“to:”,“cc:”,“href”);
return str_replace($bad,"",$string);
}
$email_message .= “Name: “.clean_string($name).”\n”;
$email_message .= “E-Mail Address: “.clean_string($eadd).”\n”;
$email_message .= “Club Name: “.clean_string($club_name).”\n”;
$email_message .= “Town / City: “.clean_string($town).”\n”;
$email_message .= “Province: “.clean_string($province).”\n”;
$email_message .= “Postal Code: “.clean_string($pcode).”\n”;
$email_message .= “Phone Number: “.clean_string($phone).”\n”;
$email_message .= “Shoot Time: “.clean_string($shoottime).”\n”;
$email_message .= “Class: “.clean_string($class).”\n”;
$email_message .= “Event: “.clean_string($event).”\n”;
$email_message .= “Comments: “.clean_string($comments).”\n”;

// This section creates the email headers
$auth = array(‘host’ => $host, ‘auth’ => true, ‘username’ => $username, ‘password’ => $password);
$headers = array(‘From’ => $from_address, ‘To’ => $email_to, ‘Subject’ => $email_subject, ‘Reply-To’ => $reply_to);

// This section send the email
$smtp = Mail::factory(‘smtp’, $auth);
$mail = $smtp->send($email_to, $headers, $email_message);

if (PEAR::isError($mail)) {?>

Unfortunately, the message could not be sent at this time. Please try again later.

<?php } else { ?>

Thank you for contacting us. We will be in touch with you very soon.

<?php } } ?>[/php]

Web Form Code:

[code]

Stavely Archery Lanes Event Registration .style1 { text-align: center; color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; } .style2 { font-family: Arial, Helvetica, sans-serif; font-size: x-large; color: #FFFFFF; } Stavely Archery Lanes Event Registration

Name:                   

E-mail Address: 

Club Name & #    

City/Town:        
 

Province:             

Postal Code:       

Phone Number:  

Shoot Time:  9:00 AM 10:15 AM 11:30 AM 9:00 AM or 11:30 AM or 10:15 AM

Class M60 Male M60 Female M50 Male M50 Female BHO Male BHO Female BHR Male BHR Female BHF Male BHF Female JRC Male JRC Female CADC Male CADC Female HUN Male HUN Female HF Male HF Female M50TR Male M50TR Female BB Male BB Female TRD Male TRD Female IN Male IN Female JRT Male JRT Female CADT Male CADT Female CUBT Male CUBT Female PCUBT Male PCUBT Female CUBC Male CUBC Female PCUBC Male PCUBC Female

Event: Stavely Archery Lanes Doug Symonds 3D Memorial Shoot Stavely Archery Lanes Annual 3D Indoor Tournament March 15th 2014 Stavely Archery Lanes 3D Outdoor Spring Shoot May 17th,18th,19th 2014

Other Information:


 
    



[/code]

Any help would be hugely appreciated!!! Merry Christmas thanks a million!

Sponsor our Newsletter | Privacy Policy | Terms of Service