As part of an online subscription page, I have a PHP mailer that sends the details the user just entered, to 2 specified email addresses. The function has been working fine as far as I can remember but since a week it somehow doesn’t.
Users get the following error message in the browser:
Failed to add recipient: yyy@yyy.nl [SMTP: Invalid response code received from server (code: 550, response: R1: HELO should be a FQDN or address literal (See RFC 2821 4.1.1.1))]_________________________________________MIME-Version: 1.0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable From: xxx@xxx.nl To: yyy@yyy.nl, zzz@zzz.com Date: Tue, 03 Jun 2014 18:18:41 +0200 Subject: Contact formulier Onderstaand bericht is op Tuesday, June 3rd, 2014 om 06:18 PM verstuurd via= het lidworden-contactformulier van de ledensite. Graag actie ondernemen! Subscribtion : Belangstellend lidmaa= tschap Surname :
Name :
Dateofbirth :
Placeofbirth :
Email :
Adres :
Postalcode :
City :
Telephone :
Mobiletelephone :
Warning: Cannot modify header information - headers already sent by (output started at /xxxxxxxxxxxxx/sendmail.php:39) in/xxxxxxxxxx.public_html/mailer.php on line 50
This is the code from the mailer.php
:
<?PHP
include("sendmail.php");
$from = “xxx@xxx.nl";
$to = “yyy@yyy.nl, zzz@zzz.com";
$subject = "Contact formulier";
$reply_to = "";
$date = date ("l, F jS, Y");
$time = date ("h:i A");
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$data = $_POST;
} else {
$data = $_GET;
}
$msg .= "<html>
<body>
Message<p>
<table>\r\n";
foreach ($data as $key => $value) {
if( strtolower($key) != "submit" ) { // Ignore submit button
$msg .= "<tr><td valign='top'>" . ucfirst ($key) . "</td><td>:</td><td>". nl2br($value) . "</td></tr>\n";
if( $key == "Email" ) {
$reply_to = $value;
}
}
}
$msg .= "</table>
</body>
</html>";
$result = sendmail($from, $to, $reply_to, $subject, $msg, "");
if( $result ) {
$location="/?page=response_success&menu=lerenvliegen";
} else {
$location="/?page=response_failure&menu=lerenvliegen";
}
header ("Location:$location");
?>
Code from sendmail.php
:
<?php
function sendmail($from, $to, $reply_to, $subject, $mailhtml) {
set_include_path("/usr/local/lib/php" . PATH_SEPARATOR . ini_get(”include_path”));
require_once 'Mail.php';
require_once 'Mail/mime.php';
$host = "localhost";
$username = "";
$password = "";
$mime = new Mail_mime();
$mime->setHTMLBody($mailhtml);
if( $reply_to != "") {
$extraheaders = array('From' => $from, 'To' => $to, 'Date' => date( 'r' ), 'Subject' => $subject, 'Reply-To' => $reply_to, 'Return-Path' => $reply_to);
} else {
$extraheaders = array('From' => $from, 'To' => $to, 'Date' => date( 'r' ), 'Subject' => $subject);
}
$recipients['To'] = $to;
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => false,
'username' => $username,
'password' => $password));
$body = $mime->get();
$headers = $mime->headers($extraheaders);
$result = $smtp->send($recipients, $headers, $body);
IF (PEAR::isError($result)):
echo $result->getMessage() . "_________________________________________" . $mime->getMessage();
return false;
ENDIF;
return true;
}
Am I missing some mistake in the code?