Jump to content

SMTP server response: 501 5.5.4 Invalid Address


jim.davidson

Recommended Posts

I have a piece of code that works on one domain but not on another.  On the domain running php 5.1 all is ok.  On the domain running php 4.4 I get this error:

 

SMTP server response: 501 5.5.4 Invalid Address

 

Hosting service keeps telling me there must be an error in the code.  If that's the case why would it work on version 5.1?

 

Here is the code, I don't know what could be wrong.  Any help will be greatly appreciated.

 

<?php

// set flag to indicate whether mail has been sent

$mailSent = false;

$sent = false;

if (array_key_exists('sendComments', $_POST)) {

  // mail processing script

  // remove escape characters from POST array

  if (get_magic_quotes_gpc()) {

    function stripslashes_deep($value) {

    $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);

    return $value;

    }

    $_POST = array_map('stripslashes_deep', $_POST);

  }

  // validate the input, beginning with name

  $name = trim($_POST['name']);

  if (empty($name)) {

    $error['name'] = 'Please enter your name';

  }

  $phone = trim($_POST['phone']);

  $email = $_POST['email'];

  // check for valid email address

  $pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/';

  if (!preg_match($pattern, trim($email))) {

    $error['email'] = 'Please enter a valid email address';

  }

  // check the content of the text area

  $messageBody = trim($_POST['message']);

  if (empty($messageBody)) {

    $error['message'] = 'Please enter your message';

  }

  // initalize variables

  $to = 'jim@independent-micro.com';

  $subject = 'Feedback from PCI-Controls web site';

  // build the message

  $message = "From: $name\n\n";

  $message .= "Email: $email\n\n";

  $message .= "Phone Number: $phone\n\n";

  $message .= "Comments: $messageBody";

  // build additional headers

  $additionalHeaders = "From: PCI Controls Web Site<$email>\r\n";

  $additionalHeaders .= "Reply-To: $email";

  // send the mail if ther are no errors

  if (!isset($error)) {

    $mailSent = mail($to, $subject, $message, $additionalHeaders);

// check to see if sent successfully

if (!$mailSent) {

  $error['notSent'] = 'Sorry there is a problem sending your message.  Please try later.';

}

else {

  $sent = true;

}

  }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.