hi..

im trying to send email to the user who register to my website..

SMTP server response: 501 5.5.4 Invalid Address in D:\Domains\\wwwroot\reg_save.php on line 66

this is the error im getting..

if($res)
{
	//echo "record added";
	//$count = 1;
	$to = $mail;
	$sub = "Confirm Mail From LeLys";
	$header = "from: LeLys<support@lelys.org>";
	
	$message = "confirm link \r\n";
	$message.= "click to activete your account \r\n";
	$message.= "";
	
	$sending = mail($to,$sub,$message,$header);
	
		if($sending)
			{
				//echo ("email comfirm");
?>
		

<body>
<table width="100%" border="0" align="center" bgcolor="#DAF5FE">
  <tr>
    <td height="233"><table width="94%" border="1" align="center" bgcolor="#F0FCFF">
      <tr>
        <td height="178"><center><h2>Your Details have been Added</h2><br />Please check for a Confirmation email</center></td>
      </tr>
    </table></td>
  </tr>
</table>
<?php
}
		else
			echo("email not sent");

}

this is the code im using..

and

$sending = mail($to,$sub,$message,$header);

this is line 66 in my code.. PLZ HELP...

Dani AI

Generated

Thread summary and focused troubleshooting

has confirmed the recipient variable contains an address (thanks to ) and a minimal test produced a different, server-side rejection (as noted by and ). The symptoms point to two separate SMTP issues: (A) the SMTP server rejecting the envelope because of address/format, and (B) the SMTP server refusing to relay because it requires authentication or a trusted envelope sender. The problem is usually server configuration rather than a PHP bug.

Quick checklist and practical fixes

  • Validate the recipient before sending (basic syntax check). For example:

    if (!filter_var($to, FILTER_VALIDATE_EMAIL)) {
        // stop and log invalid address
    }
  • Build headers correctly and use CRLF line endings (especially on Windows). If sending HTML, set a Content-Type header. Example header assembly:

    $headers  = "From: LeLys <support@lelys.org>\r\n";
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
  • Envelope sender: on Windows PHP uses the php.ini settings (sendmail_from / SMTP). Make sure the envelope sender domain is acceptable to the SMTP server. On Unix you can also set the envelope with the extra mail parameter, but that is not available the same way on Windows.

When relay/authentication is required

If the SMTP server requires authentication (common for preventing open relay) the built-in mail() on many Windows hosts cannot do SMTP AUTH. The practical options are:

  • Configure the host SMTP service or php.ini so the host accepts mail from your script (requires host support).
  • Use a library that implements authenticated SMTP (for example, PHPMailer) and send via authenticated SMTP credentials.

Where to look next

  • Check the webhost/SMTP logs or ask support and provide the exact SMTP response lines (MAIL FROM / RCPT TO / 5xx replies).
  • If you switch to an SMTP library, enable debugging to capture the SMTP conversation; that will show whether the server rejects MAIL FROM or RCPT TO and why.

References: PHP mail() behavior and configuration are documented here: PHP mail() manual. For authenticated SMTP libraries, see PHPMailer on GitHub.

Recommended Answers

All 7 Replies

Well try adding the following line just before the mail function to see if the address to is being stored properly.

echo '<h1>'.$to.'</h1>';

It should display the email address and if it doesn't then your problem is that the variable $mail hasn't got any email address assigned.

i tried it..

the email id is echoed prefectly in <h1> tags...

still get the same error,,

SMTP server response: 501 5.5.4 Invalid Address in D:\Domains\\wwwroot\reg_save.php on line 66

Well try commenting the following line and also make sure the to address is valid.

$header = "from: LeLys<support@lelys.org>";

Also, try sending a simple mail to see if it works.

<?php
mail("youraddress@domain.com","test","test mail ! Hope it works","from: youraddress@domain.com");
?>

If it does, then its obvious that you missed out something in your other script.

hi guys...

i changed the code as u said n tested it..

now im getting a different error..

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay

wat do this thing means ?

im totally stuck wit this thing.. cant now forward with this prob..

If you tried nav33n's script and got that error first I would suggest to make sure the two email addresses in his code are not the same and are valid email addresses. If the problem continues then try contacting your web host as their SMTP server may need configuring. Also include in the email to your web host nav33n's code but with the real email addresses which do not match.

Many Internet Service Providers (ISP's) require that you send your username and password before you are allowed to send email. This is called "Authentication" or "SMTP Auth".

More recently, some ISP's have begun to require that you have TWO separate and different login names - one for checking mail and one for sending mail. This is called "SMTP Relay".
So there might be the problem with your smtp server settings, check with it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.