PhpMailer.php not sending emails.  How do I set it up properly?

dthardy
dthardy used Ask the Experts™
on
I am trying to create a form that follows the example at http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/ .

Everything works great except phpmailer.  I believe it must be something in my set up in my process.php page.  I have verified that the username, password, port, host, etc. is correct. I have changed them in the attached code for security.

Is there something wrong in my setup of phpmailer?

I have attached the code for process.php which calls phpmailer.php.  I have not changed anything in phpmailer.
<?php
if ((isset($_POST['forklifttype'])) && (strlen(trim($_POST['forklifttype'])) > 0)) {
	$forklifttype = stripslashes(strip_tags($_POST['forklifttype']));
}
if ((isset($_POST['engine'])) && (strlen(trim($_POST['engine'])) > 0)) {
	$engine = stripslashes(strip_tags($_POST['engine']));
}
if ((isset($_POST['tires'])) && (strlen(trim($_POST['tires'])) > 0)) {
	$tires = stripslashes(strip_tags($_POST['tires']));
}
if ((isset($_POST['capacity'])) && (strlen(trim($_POST['capacity'])) > 0)) {
	$capacity = stripslashes(strip_tags($_POST['capacity']));
}
if ((isset($_POST['height'])) && (strlen(trim($_POST['height'])) > 0)) {
	$height = stripslashes(strip_tags($_POST['height']));
}
if ((isset($_POST['interest'])) && (strlen(trim($_POST['interest'])) > 0)) {
	$interest = stripslashes(strip_tags($_POST['interest']));
}
if ((isset($_POST['qty'])) && (strlen(trim($_POST['qty'])) > 0)) {
	$qty = stripslashes(strip_tags($_POST['qty']));
}
if ((isset($_POST['buy'])) && (strlen(trim($_POST['buy'])) > 0)) {
	$buy = stripslashes(strip_tags($_POST['buy']));
}
if ((isset($_POST['timeframe'])) && (strlen(trim($_POST['timeframe'])) > 0)) {
	$timeframe = stripslashes(strip_tags($_POST['timeframe']));
}
if ((isset($_POST['additional'])) && (strlen(trim($_POST['additional'])) > 0)) {
	$additional = stripslashes(strip_tags($_POST['additional']));
} else {$phone = 'No additional comments entered';}
if ((isset($_POST['full_name'])) && (strlen(trim($_POST['full_name'])) > 0)) {
	$full_name = stripslashes(strip_tags($_POST['full_name']));
}
if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) {
	$email = stripslashes(strip_tags($_POST['email']));
}
if ((isset($_POST['phone'])) && (strlen(trim($_POST['phone'])) > 0)) {
	$phone = stripslashes(strip_tags($_POST['phone']));
}
if ((isset($_POST['company'])) && (strlen(trim($_POST['company'])) > 0)) {
	$company = stripslashes(strip_tags($_POST['company']));
}
if ((isset($_POST['postal'])) && (strlen(trim($_POST['postal'])) > 0)) {
	$postal = stripslashes(strip_tags($_POST['postal']));
}
$formTime = date('l, F d, Y  h:i a', time());
$leadNum = time();
ob_start();
?>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<table width="550" border="1" cellspacing="2" cellpadding="2">
  <tr>
  	<td>
    Dear ,

	<p>Here is another valuable ForkliftBuy.com quote request for Forklifts.</p>
    <p>Quick Start Success Guide<br />
    ============================</p>
    1. Act immediately on the quote request.<br />
	2. Review the buyer's contact and purchasing requirements thoroughly.<br />
    3. Contact the buyer as soon as possible.<br />
	4. Tell the buyer that you are replying to their quote request from ForkliftBuy.com.<br />
    </p>
    <p>
    =============================<br />
    BUYER CONTACT INFORMATION<br />
    =============================<br />
    </p>
    <p>&nbsp;</p>
    </td>
    <td>&nbsp;</td>
  </td>
  <tr bgcolor="#eeeeff">
  	<td>Lead Number:</td>
    <td>&nbsp;&nbsp;<?=$leadNum;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Buyer Name:</td>
    <td>&nbsp;&nbsp;<?=$full_name;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Company:</td>
    <td>&nbsp;&nbsp;<?=$company;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Email:</td>
    <td>&nbsp;&nbsp;<?=$email;?></td>
  </tr>
    <tr bgcolor="#eeffee">
    <td>Phone:</td>
    <td>&nbsp;&nbsp;<?=$phone;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Zip Code:</td>
    <td>&nbsp;&nbsp;<?=$postal;?></td>
  </tr>
  <tr>
  	<td>
    <p>
    =============================<br />
    QUOTE INFORMATION<br />
    =============================<br />
    </p>
    <p>&nbsp;</p>
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Number of forklifts needed:</td>
    <td>&nbsp;&nbsp;<?=$qty;?></td>
  </tr>
    <tr bgcolor="#eeffee">
    <td>New or Used condition:</td>
    <td>&nbsp;&nbsp;<?=$interest;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Prefered purchase method:</td>
    <td>&nbsp;&nbsp;<?=$buy;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>What is the buyer's time frame:</td>
    <td>&nbsp;&nbsp;<?=$timeframe;?></td>
  </tr>
    <tr bgcolor="#eeeeff">
    <td>What type of forklift is required:</td>
    <td>&nbsp;&nbsp;<?=$forklifttype;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Approximate capacity range:</td>
    <td>&nbsp;&nbsp;<?=$capacity;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>What type of engine or power:</td>
    <td>&nbsp;&nbsp;<?=$engine;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>What is the preferred tire type:</td>
    <td>&nbsp;&nbsp;<?=$tires;?></td>
  </tr>
    <tr bgcolor="#eeffee">
    <td>Approximate Lift Height required:</td>
    <td>&nbsp;&nbsp;<?=$height;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Additional Requirements:</td>
    <td>&nbsp;&nbsp;<?=$additional;?></td>
  </tr>
  <tr>
  	<td>===============================================</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
<?
$body = ob_get_contents();
$host = 'mail.myserver.com';
$to = 'me@email.com';
$engine = 'me@engine.com';
$fromaddress = 'mail@mail.com';
$fromname = 'Mail';
$username = 'myusername';
$password = 'imypassword';
//$port = 2525;
$subject =  "Request" . $leadNum;


require("phpmailer.php");

$mail = new PHPMailer();

$mail->From     = $fromaddress;
$mail->FromName = $fromname;
//$mail->AddAddress("engine_address@example.com","Name 1");
//$mail->AddAddress("another_address@example.com","Name 2");
$mail->Host = $host;
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
//$mail->Port = $port;


$mail->Subject  =  $subject;
$mail->Body     =  $body;
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send()) {
	$recipient = $to;
	$subject = 'Contact form failed';
	$content = $body;	
  mail($recipient, $subject, $content, "From: mail@forkliftbuy.com\r\nReply-To: $engine\r\nX-Mailer: DT_formmail");
  exit;
}

?>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Can you post any errors your getting on screen or in the logs? If your not getting any errors put the below code in the top of your page and try send a mail.

<?php error_reporting(E_ALL); ?>

Author

Commented:
ziycon,

I was not receiving any errors so I did as you said, but continue to receive no errors on the page or in my Firefox error console. No errors when running in IE.

You can try it out at http://forkliftbuy.com/Form/bin/process.php
Commented:
I am closing this question. Dropped phpMailer and moved to Swift Mailer with everything working smoothly.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial