Bad adress syntax
Posted by: psn (---.tbcn.telia.com)
Date: March 07, 2008 07:49AM

Hi,

I have a problem regarding the From part seems not working in the mail() when running on windows. I got the errormsg:

Warning: mail() [function.mail]: SMTP server response: 501 Bad address syntax in E:\wamp\www\vagaraddaliv\includes\check_contacts.php on line 114

Is there any solution to fix this in the settings?

Regards/Per

Options: ReplyQuote
Re: Bad adress syntax
Posted by: psn (194.202.236.---)
Date: March 07, 2008 01:51PM

Hi again, it seems that windows doesn't handle just the From as name, it should work just to put in the actual mail address and skip the name part. But do any one have other solutions if I wan't to keep this name function to work?

//Per

Options: ReplyQuote
Re: Bad adress syntax
Posted by: yfastud (Moderator)
Date: March 07, 2008 04:24PM

Actually, wamp does not come w/ any mail server

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: Bad adress syntax
Posted by: psn (---.tbcn.telia.com)
Date: March 07, 2008 06:04PM

I know that, but the question is if its possible to have the From: Name <address> at all when I have istall the wampserver on windows? (Its working fine if I just have From: address into the mail() function)

Options: ReplyQuote
Re: Bad adress syntax
Posted by: toivo (---.nsw.bigpond.net.au)
Date: March 07, 2008 09:52PM

Hi,

According to the PHP documentation at [php.net], you can use the format User <user@example.com> in the to: address. It also refers to the RFC settings in [www.faqs.org]. The STMP settings section in the manual does not refer to the RFC.

You could have a look at the code in the PHP module check_contacts.php to see which mailer it uses and see if you can use phpMailer() class which may possibly solve your problem.

Regards,

toivo
Sydney, Australia

Options: ReplyQuote
Re: Bad adress syntax
Posted by: psn (---.tbcn.telia.com)
Date: March 07, 2008 11:19PM

Hi Toivo,

I'm not so sure that I understand your last part, phpMailer() class?

How can this part solve my problem? Can you show me an example?

Regards/Per

Options: ReplyQuote
Re: Bad adress syntax
Posted by: toivo (---.nsw.bigpond.net.au)
Date: March 07, 2008 11:44PM

Hi,

Have a look at the PHP source code of phpMailer, from [phpmailer.codeworxtech.com]. A number of CMS applications use it because of its versatility and features, which include attachments and HTML messages.

By the way, looking at the mail() function, the manual says "This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n).". The extra header could be the solution to your particular problem, assuming that the extra From: header overrides the SMTP setting.

You need to look at the PHP code in your application where it sets the parameters to the mail() function or whichever mailer it is using. What is the application, or did you write it?

Regards,

toivo
Sydney, Australia

Options: ReplyQuote
Re: Bad adress syntax
Posted by: psn (---.tbcn.telia.com)
Date: March 08, 2008 01:54AM

I have written the check_contacts.php and its based on a normal form where the user put in his name, mailaddress which come doown to th mail() function. So normally I use this code:

<?php
$_SESSION["Namn"] = $_POST["Namn"];
$_SESSION["Tel"] = $_POST["Tel"];
$_SESSION["Epost"] = $_POST["Epost"];
$_SESSION["Antal"] = $_POST["Antal"];
//kontaktmail
if ($submit) {
//Checks the name
$errors = array();
$namncheck = trim($_POST["Namn"], " \-"winking smiley;
if (!preg_match("/^[a-zA-ZåäöÅÄÖüÜéÉèÈôÔ\-]+[a-zA-ZåäöÅÄÖüÜéÉèÈôÔ\- ]+$/i", $namncheck))
$errors[0] = '<span style="float: left"><img src="bilder/warning_obj.gif" alt="Error" title="Error"/></span> ditt namn innehåller ogiltiga tecken eller ev blanksteg, endast A-Ö accepteras';
//Check the phone number
$telcheck = $_POST["Tel"];
if(!preg_match("/^\+46\([1-9][0-9]*\)\d{5,}$|^\+46[1-9]\d{5,}$|^0[1-9]+\d{5,}$|^0[1-9][0-9]*-\d{5,}$/", $telcheck))
$errors[1] = '<span style="float: left"><img src="bilder/warning_obj.gif" alt="Error" title="Error"/></span> ditt telnr saknas eller är felaktigt, skriv ex 08-121212, 08121212, +468121212 eller +46(8)121212';
//Check the email
$emailcheck = $_POST["Epost"];
if(!preg_match("/^[a-z0-9\å\ä\ö._-]+@[a-z0-9\å\ä\ö.-]+\.[a-ö]{2,6}$/i", $emailcheck))
$errors[2] = '<span style="float: left"><img src="bilder/warning_obj.gif" alt="Error" title="Error"/></span> din epostadress saknas eller är felaktig';
}
?>

<form action="<?php PHP_SELF ?>" method="post" name="kontakt">
<div align="left">Namn:*</div>
<div align="left"><input type="text" name="Namn" class="<?php if($errors[0]){ echo "bakgrund_error"; } else { echo "bakgrund"; } ?>" id="theField_name" value="<?php if(count($errors)>0) echo isset($_SESSION["Namn"]) ? $_SESSION["Namn"] : ''; ?>"/>
<?php if(!$errors[0] && !$submit){
echo '<script type="text/javascript">
document.getElementById("theField_name"winking smiley.focus();
</script>
<noscript>&nbsp;</noscript>';
}
?>
<?php if($errors[0]){
echo '<script type="text/javascript">
document.getElementById("theField_name"winking smiley.select();
</script><noscript>&nbsp;</noscript>';
}
?>
</div>
<div align="left">Tel:*</div>
<div align="left"><input name="Tel" type="text" class="<?php if($errors[1]){ echo "bakgrund_error"; } else { echo "bakgrund"; } ?>" id="theField_tel" value="<?php if(count($errors)>0) echo isset($_SESSION["Tel"]) ? $_SESSION["Tel"] : ''; ?>"/>
<?php if($errors[1]){
echo '<script type="text/javascript">
document.getElementById("theField_tel"winking smiley.select();
</script><noscript>&nbsp;</noscript>';
}
?>
</div>
<div align="left">Epost:*</div>
<div align="left"><input type="text" name="Epost" class="<?php if($errors[2]){ echo "bakgrund_error"; } else { echo "bakgrund"; } ?>" id="theField_epost" value="<?php if(count($errors)>0) echo isset($_SESSION["Epost"]) ? $_SESSION["Epost"] : ''; ?>"/>
<?php if($errors[2]){
echo '<script type="text/javascript">
document.getElementById("theField_epost"winking smiley.select();
</script><noscript>&nbsp;</noscript>';
}
?>
</div>
<div align="left">Antal personer:</div>
<div align="left"><input type="text" name="Antal" class="bakgrund" value="<?php if(count($errors)>0) echo isset($_SESSION["Antal"]) ? $_SESSION["Antal"] : ''; ?>" onkeyup="if(!this.value.match(/^\d+$/)){ this.value=(this.value.match(/\d+/))?this.value.match(/\d+/):''; }"/></div>
<br/>
<div align="left">&Ouml;nskar offert/information p&aring; f&ouml;ljande utbildningsavsnitt:</div>
<div align="left"><input type="checkbox" name="grund_hlr" value="Grund-HLR" class="bakgrund"/>Grund-HLR<br/>
<input type="checkbox" name="d_hlr" value="D-HLR" class="bakgrund"/>D-HLR<br/>
<input type="checkbox" name="s_hlr" value="S-HLR" class="bakgrund"/>S-HLR<br/>
<!--<input type="checkbox" name="a_hlr" value="A-HLR" class="bakgrund"/>A-HLR<br/> OM denna läggs till glöm inte att lägg in denna i mail()!-->
<input type="checkbox" name="barn_hlr" value="Barn-HLR" class="bakgrund"/>Barn-HLR</div>
<br/>
*=Obligatorisk uppgift!<br/>
<br/>
<?php if($submit){
if($errors[0]){
echo '<script type="text/javascript">
document.getElementById("theField_name"winking smiley.focus();
document.getElementById("theField_name"winking smiley.select();
</script><noscript>&nbsp;</noscript>';
}
elseif($errors[1]){
echo '<script type="text/javascript">
document.getElementById("theField_tel"winking smiley.focus();
document.getElementById("theField_tel"winking smiley.select();
</script><noscript>&nbsp;</noscript>';
}
elseif($errors[2]){
echo '<script type="text/javascript">
document.getElementById("theField_epost"winking smiley.focus();
document.getElementById("theField_epost"winking smiley.select();
</script><noscript>&nbsp;</noscript>';
}
}
?>


<input name="submit" type="submit" value="Skicka" class="bakgrund"/><br/>
<br/>
</form>

<?php

if($submit){

// If something goes wrong show this msg
if (count($errors)>0) {
echo "<b>OBS! Obligatorisk information saknas:</b><br/>";
echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"75%\" summary=\"Felkontroll\">";
echo "<tr><td align=\"left\">";

foreach($errors as $fel)
echo "$fel<br/>";
echo "</td></tr>";
echo "</table>";
echo "<br />Ange den information som saknas och skicka formuläret igen. Tack! <br />";
} else {
mail("inger@test.se","Kontakt önskas","Kontakta: $Namn på $Tel för följande kurs:\r$grund_hlr\r$d_hlr\r$s_hlr\r$barn_hlr\r\rAntal personer: $Antal","From:$Namn<$Epost>"winking smiley;
mail("ingerm.olson@test.com","Kontakt önskas","Kontakta: $Namn på $Tel för följande kurs:\r$grund_hlr\r$d_hlr\r$s_hlr\r$barn_hlr\r\rAntal personer: $Antal","From:$Namn<$Epost>"winking smiley;
echo "<b>OBS!</b> Meddelandet skickat och vi kommer kontakta er inom kort!";
session_unset();
session_destroy();

}
}

?>

The production site is placed on a linux server so therefore I don't have any problem with From: $Namn<$Epost>. I don't have any mailserver so I'm using a third parties server here. Some of the text is in swedish but I think you should understand the majority of it.



Edited 1 time(s). Last edit at 03/08/2008 01:56AM by psn.

Options: ReplyQuote
Re: Bad adress syntax
Posted by: toivo (---.nsw.bigpond.net.au)
Date: March 08, 2008 10:36PM

Hi Per,

Du har rätt, jag kan läsa svenska.

If you send the individual From: address as part of the header information in the mail() function, it will not use the default sendmail_from from the STMP settings in php.ini.

Do you grab the $EPost variable from $_POST or the form by having register_globals ON? This variable seems to contain the email address of the person who filled in the contact form, and this email address may not belong to the domain where your server is. Are you sure the SMTP server your WAMP server uses accepts mail from anyone? Some STMP servers expect the From: address to be in your server domain, otherwise they think you try to use their server for relaying messages.

If your problem is caused by the format of the address rather than the SMPT server rejecting mail that it thinks is being relayed, you could use the fopen and fwrite functions to write the email addresses to a text file and then check the precise format that is being sent to the SMTP server.

Last, but not least: In the code, after the line $emailcheck = $_POST["Epost"]; you validate the email address which is sent with the person's name as part of the from: header. The pattern includes the Scandinavian characters å, ä and ö. However, if you check the RFC for Internet Message Format or the STMP specification RFC2822 from [www.faqs.org], it only accepts the US ASCII (see [en.wikipedia.org]) printable characters, which do not include those three characters. Does your SMTP server accept addresses with these characters? How about the SMTP server at the receiving end which may not be hosted in Scandinavia?

Med Vänliga Hälsningar,

toivo
Sydney, Australia



Edited 1 time(s). Last edit at 03/08/2008 10:39PM by toivo.

Options: ReplyQuote


Sorry, only registered users may post in this forum.