Reputation: 506
I'm creating a contact us form, which should e-mail me the contents of the form. I tried to send mail on my localhost, and it didn't work, but it works perfectly when on a host (1and1). Now, I'm trying it out on a new host (Netfirms). FOr some apparent reason, the mail function doesn't send the mail, and it doesn't return a true/false value. I've tried googling a solution or a theory all night, but it was no use. What could be causing this weird result?
Here is the PHP for the mailing.
<?php
class zMail {
final public function compileMail() {
global $tpl, $zip;
$tpl->Define('error', null);
# Ensure that the form was sent #
if(isset($_POST['contact-us'])) {
# Make sure that the variables are set for the mailing process #
$first_name = $_POST['f_name'];
$last_name = $_POST['l_name'];
$event_type = $_POST['event'];
$date = $_POST['date'];
$guests = $_POST['guests'];
$from = $_POST['email'];
$phone = $_POST['phone'];
# Place Where E-Mail should be sent to #
$to = $zip['Social']['Email'];
# Are all fields completed? #
if(!empty($first_name) && !empty($last_name) && !empty($event_type) && !empty($date) && !empty($guests) && !empty($from) && !empty($phone)) {
switch($event_type) {
case '1':
return 'Baby Shower';
break;
case '2':
return 'Wedding';
break;
case '3':
return 'Kids Party';
break;
case '4':
return 'Birthday';
break;
case '5':
return 'Other';
break;
}
switch($guests) {
case '1':
return '10-25 People';
break;
case '2':
return '25 - 50 People';
break;
case '3':
return '50 - 75 People';
break;
case '4':
return '75 - 100+ People';
break;
}
$message = '<ul>
<li><b>First & Last Name: </b><span style="float: right;">' . $first_name . ' ' . $last_name . '</span></li>
<li><b>Event Type: </b><span style="float: right;">' . $event_type . '</span></li>
<li><b>Date: </b><span style="float: right;">' . $date . '</span></li>
<li><b>Guests: </b><span style="float: right;">' . $guests . '</span></li>
<li><b>Email: </b><span style="float: right;">' . $from . '</span></li>
<li><b>Telephone: </b><span style="float: right;">' . $phone . '</span></li>
<li><b>Add`l Information: </b><span style="float: right;">' . $notes . '</span></li>
</ul>';
$subject = "{site: title} - New Client Inquiry";
$headers = "From: [email protected]\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
$retval = mail($to, $subject, $message, $headers);
if($retval == true) {
$tpl->Define('error', '<span class="error">Message sent successfully!</span>');
} else {
$tpl->Define('error', '<span class="error">Email could not be sent!</span>');
}
} else {
$tpl->Define('error', '<span class="error">Please fill in all fields!</span>');
}
}
}
}
?>
Upvotes: 0
Views: 1581
Reputation: 2118
So I'm curious how this ever worked on the other host. You are exiting out of the function before you ever get to the mail function.
Your two switch statements:
switch($event_type) {
case '1':
return 'Baby Shower';
break;
case '2':
return 'Wedding';
break;
case '3':
return 'Kids Party';
break;
case '4':
return 'Birthday';
break;
case '5':
return 'Other';
break;
}
switch($guests) {
case '1':
return '10-25 People';
break;
case '2':
return '25 - 50 People';
break;
case '3':
return '50 - 75 People';
break;
case '4':
return '75 - 100+ People';
break;
}
These are returning strings, which means as long as a case was matched, NO code after the switch statements will ever get executed.
Maybe you are trying to redefine the variables like so:
switch($event_type) {
case '1':
$event_type = 'Baby Shower';
break;
case '2':
$event_type = 'Wedding';
break;
case '3':
$event_type = 'Kids Party';
break;
case '4':
$event_type = 'Birthday';
break;
case '5':
$event_type = 'Other';
break;
}
switch($guests) {
case '1':
$guests = '10-25 People';
break;
case '2':
$guests = '25 - 50 People';
break;
case '3':
$guests = '50 - 75 People';
break;
case '4':
$guests = '75 - 100+ People';
break;
}
Upvotes: 2
Reputation: 351
Have you checked if port 25 is open? Here is a link: http://www.yougetsignal.com/tools/open-ports/
Upvotes: 0