I've been trying to utilize a mail.php file from the jquery contactable plugin (found on google!) to use on my website. Although the script provided is fairly simple I'm running into issues with integrating it with my Host's SMTP requirement. Here is the original script without SMTP authentication:
<?php
// Assign contact info
$name = stripcslashes($_POST['name']);
$emailAddr = stripcslashes($_POST['email']);
$issue = stripcslashes($_POST['issue']);
$comment = stripcslashes($_POST['message']);
$subject = stripcslashes($_POST['subject']);
// Set headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Format message
$contactMessage =
"<div>
<p><strong>Name:</strong> $name <br />
<strong>E-mail:</strong> $emailAddr <br />
<strong>Issue:</strong> $issue </p>
<p><strong>Message:</strong> $comment </p>
<p><strong>Sending IP:</strong> $_SERVER[REMOTE_ADDR]<br />
<strong>Sent via:</strong> $_SERVER[HTTP_HOST]</p>
</div>";
// Send and check the message status
$response = (mail('[email protected]', $subject, $contactMessage, $headers) ) ? "success" : "failure" ;
$output = json_encode(array("response" => $response));
header('content-type: application/json; charset=utf-8');
echo($output);
?>
I've tried using suggestions from Google and played around with it for hours. Here is the latest version based on my nil-understanding of php thus far. -__- (Based on this: http://blog.geek4support.com/php-mail-script-with-smtp-authentication-how-to-send-mails-by-php-mail-script-using-smtp-authetication/)
<?php
require_once "Mail.php";
// Assign contact info
$name = stripcslashes($_POST['name']);
$emailAddr = stripcslashes($_POST['email']);
$issue = stripcslashes($_POST['issue']);
$comment = stripcslashes($_POST['message']);
$subject = stripcslashes($_POST['subject']);
$host = "mail.mywebsite.com";
$username = "[email protected]";
$password = "mymailpassword";
// Set headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Format message
$contactMessage =
"<div>
<p><strong>Name:</strong> $name <br />
<strong>E-mail:</strong> $emailAddr <br />
<strong>Issue:</strong> $issue </p>
<p><strong>Message:</strong> $comment </p>
<p><strong>Sending IP:</strong> $_SERVER[REMOTE_ADDR]<br />
<strong>Sent via:</strong> $_SERVER[HTTP_HOST]</p>
</div>";
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$response = ($smtp->send('[email protected]', $subject, $contactMessage, $headers)) ? "success": "failure";
$output = json_encode(array("response" => $response));
header('content-type: application/json; charset=utf-8');
echo($output);
?>
I've actually run into a bit of a problem. My host doesn't support PHPMailer :-(. Only PearMail with SMTP. They have suggested tweaking the code listed above and incorporating my existing one with it. Exactly, what I've been trying to do before posting this online. Back to square 1, any ideas?
Comments, suggestions, anything would be most appreciated! :-)