Hello all,
I was on here a few months ago to get help resolving a contact form issue, and with the generous help and expertise of the forum, I was able to get it all resolved. But, this contact form has reared its ugly head again!
It was recommended that I upgrade my PHP version on my VPS, so I did so with the help of the tech support team with my hosting company. They mentioned that existing scripts may break as a result of the upgrade, and I suspect that's the case here. My server has been upgraded to PHP version 5.3.16.
When a visitor to the contact page attempts to submit the form, they receive the following error:
Fatal error: Call to undefined method Net_SMTP::getGreeting() in /usr/local/cpanel/3rdparty/lib/php/Mail/smtp.php on line 316
It's not that "fatal" however, as the email gets posted and my client receives it fine. The visitor, though, thinking it's an issue with the form/browser, attempts to resend the contact form (multiple times!), flooding my client with repeat messages.
Here's the script:
<?php
require_once 'Mail.php';
$from = "mail@domain.com";
$to = "client@otherdomain.com";
$subject = "Website Contact Form";
$name = Trim(stripslashes($_POST['Name']));
$phone = Trim(stripslashes($_POST['Phone']));
$email = Trim(stripslashes($_POST['Email']));
$replyTo = $email;
$message = Trim(stripslashes($_POST['Message']));
// smtp requirements
$host = "mail.domain.com";
$username = "user";
$password = "pass";
function formatPhone($num) {
$num = ereg_replace('[^0-9]', '', $num);
$len = strlen($num);
if($len == 7)
$num = preg_replace('/([0-9]{3})([0-9]{4})/', '$1-$2', $num);
elseif($len == 10)
$num = preg_replace('/([0-9]{3})([0-9]{3})([0-9]{4})/', '($1) $2-$3', $num);
return $num;
}
// prepare email body text
$body = "";
$body .= "Name: ";
$body .= $name;
$body .= "\n";
$body .= "Phone: ";
$body .= formatPhone($phone);
$body .= "\n";
$body .= "Email: ";
$body .= $email;
$body .= "\n";
$body .= "Message: ";
$body .= $message;
$body .= "\n";
$headers = array ('From' => $from,
'To' => $to,
'Reply-To' => $replyTo,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
?>
Any ideas on what's breaking this script all of a sudden with the upgraded version of PHP?
Thanks in advance for any advice!
Mindy 🙂