Topic: mail header issue (am i going crazie?!) (Read 959 times)
What a dork
Posts: 17
110 credits Members referred : 0
« on: Aug 09, 2006, 02:53:27 AM »
I get an error dealing with this line: $header = "From: \" " . $this->webmaster_name . " \" <".$this->webmaster_mail.">\r\n"; (in the access_user_class.php)
When I replace that line with this: $header = "From: mymail@hotmail.com\r\n"; It works like a charm. How come only I have trouble with this line?
The variables are all fine... it seems that after the less-than-sign (quote: <".$this-) the whole string turns into an html tag? - I use WAMP 5 , PHP version 5...
I cannot believe I am the only one with this problem...
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6280
38506 credits Members referred : 374
I get an error dealing with this line: $header = "From: \" " . $this->webmaster_name . " \" <".$this->webmaster_mail.">\r\n"; (in the access_user_class.php)
When I replace that line with this: $header = "From: mymail@hotmail.com\r\n"; It works like a charm. How come only I have trouble with this line?
The variables are all fine... it seems that after the less-than-sign (quote: <".$this-) the whole string turns into an html tag? - I use WAMP 5 , PHP version 5...
I cannot believe I am the only one with this problem...
please post the code and you form (or the url to the form)
What a dork
Posts: 17
110 credits Members referred : 0
« Reply #2 on: Aug 09, 2006, 09:12:36 PM »
When I use this function(lines 458-475 in access_user_class.php): function send_mail($mail_address, $msg = 29, $subj = 28, $send_admin = false) { $header = "From: \"".$this->webmaster_name."\" <".$this->webmaster_mail.">\r\n";
$header = "From: ".$this->webmaster_mail."\r\n"; //my only modification
And run http://localhost/classes/register.php it results in a HTML webpage: <p><b>Please check your e-mail and follow the instructions.</b></p> etc. etc. Everything worked fine!!!
But when I use this function(lines 458-472 in access_user_class.php), minus my line: function send_mail($mail_address, $msg = 29, $subj = 28, $send_admin = false) { $header = "From: \"".$this->webmaster_name."\" <".$this->webmaster_mail.">\r\n"; if ($send_admin) $header .= "Bcc: ".ADMIN_MAIL."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Mailer: Olaf's mail script version 1.11\r\n"; $header .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n"; $subject = $this->messages($subj); $body = $this->messages($msg); if (mail($mail_address, $subject, $body, $header)) { return true; } else { return false; } }
And run http://localhost/classes/register.php again, I get this SMTP error message (smtp: mail.chello.nl): Warning: mail() [<a href='function.mail'>function.mail</a>]: SMTP server response: 550 Sender address is invalid in C:\wamp\www\classes\access_user\access_user_class.php on line 467
Now I already did some debugging and my temporary conclusion is: <" is interpreted as a tag outside the string in line 459 of the function.
I use PHP 5.1.4, Apache 2.5.55 on Windows XP SP2, MySQL 5.0.21
Can I replace the < symbol with str_replace()? Hope you have some insight...
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6280
38506 credits Members referred : 374
It's time to use PHP5!
« Reply #3 on: Aug 09, 2006, 10:35:28 PM »
this not a problem with the script, try the same code at your remote host.
(the problem is that Chello blocks smtp calls like the most other providers)
or try to send some mail with simple scripts and play with you php settings...
What a dork
Posts: 17
110 credits Members referred : 0
« Reply #4 on: Aug 10, 2006, 08:37:28 AM »
No, chello smtp does relay my mail really well (no authentication needed). Using this line: $header = "From: ".$this->webmaster_mail."\r\n"; //my only modification Puts out: From: yourname@yourdomain.com And works perfect! Before I posted yesterday I tested it to be 100% sure and the mails arrive every time.
Using this line: $header = "From: \"".$this->webmaster_name."\" <".$this->webmaster_mail.">\r\n"; Puts out: From: "The webmaster" And that is why I get: SMTP server response: 550 Sender address is invalid The question is how do I get: From: "The webmaster" <yourname@yourdomain.com> Instead of only: From: "The webmaster"
« Last Edit: Aug 10, 2006, 08:53:44 AM by scooter »
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6280
38506 credits Members referred : 374
It's time to use PHP5!
« Reply #5 on: Aug 10, 2006, 09:07:55 AM »
The full "from" header is the name and the email address, I think in your case there is a diifferent problem (I saw before):
Code:
<?php mail("nobody@example.com", "the subject", $message, "From: webmaster@{$_SERVER['SERVER_NAME']}", "-fwebmaster@{$_SERVER['SERVER_NAME']}"); ?>
note the "-f" and the return path...I don't think it's about the quotes
What a dork
Posts: 17
110 credits Members referred : 0
« Reply #6 on: Aug 11, 2006, 01:02:55 AM »
Thanks for the example Olaf. It worked perfectly (mail arrived in my mailbox). I had to replace webmaster@localhost with a real e-mail address though.
I know the proplem is and remains this line: $header = "From: \"".$this->webmaster_name."\" <".$this->webmaster_mail.">\r\n";
And I know the output of this line is: From: "The webmaster"
I know my PHP setup interprets this <" as a tag and escapes the string. When I change it to < " than it doesn't escape the string, but the e-mail address becomes meaningless.
I am clueless how I can solve that and why others don't seem to have it?
« Last Edit: Aug 11, 2006, 01:07:10 AM by scooter »
What a dork
Posts: 17
110 credits Members referred : 0
« Reply #7 on: Aug 11, 2006, 01:34:47 AM »
Olaf, I just had an idea...
Apparently the Chello smtp is perfectly willing to relay your mail when you use this convention: From: yourmail@yourdomain.com
However when you use this (more common) convention: From: "Any name" <yourmail@yourdomain.com>
mail.chello(.nl) does NOT like it. You were right when you said:"try the same code at your remote host."
The only thing I don't know is why chello smtp works this way, specially concidering that chello doen't ask for server (SMTP) verification???
Thanks for your quick help Olaf. I am a newby to PHP and web apps (I am a VBA junkie) but I hope to return the favor some time when I write my first class for some application.
-Scooter
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6280
38506 credits Members referred : 374
Thanks for the example Olaf. It worked perfectly (mail arrived in my mailbox). I had to replace webmaster@localhost with a real e-mail address though.
I know the proplem is and remains this line: $header = "From: \"".$this->webmaster_name."\" <".$this->webmaster_mail.">\r\n";
And I know the output of this line is: From: "The webmaster"
I know my PHP setup interprets this <" as a tag and escapes the string. When I change it to < " than it doesn't escape the string, but the e-mail address becomes meaningless.
I am clueless how I can solve that and why others don't seem to have it?
sending mails is sometimes reallt strange... I think that I will write a port for access_user to use a bigger e-mailer project with more mail functions (sending mail via smtp etc)
What a dork
Posts: 17
110 credits Members referred : 0
« Reply #10 on: Aug 11, 2006, 04:03:47 PM »
I tried it: $header = "From: ".$this->webmaster_name." <".$this->webmaster_mail.">\r\n"; Results in: Warning: mail() [function.mail]: SMTP server response: 550 Sender address is missing a domain Apperantly chello interpretes The webmaster as the from e-mail address.
The only thing that works with chello is this line: $header = "From: ".$this->webmaster_mail."\r\n";
More mail functions sounds great. Personaly I am planning on slightly rewriting your Access_user class so that your e-mail address is your login. For some smaller applications user tend to prefer that so they don't have to remember their username for every site (MSN messenger uses this convention, come to think of it).
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6280
38506 credits Members referred : 374
It's time to use PHP5!
« Reply #11 on: Aug 11, 2006, 05:20:29 PM »
Quote
More mail functions sounds great. Personaly I am planning on slightly rewriting your Access_user class so that your e-mail address is your login. For some smaller applications user tend to prefer that so they don't have to remember their username for every site (MSN messenger uses this convention, come to think of it).
That's an good idea but write an extension because only a few methods need be rewritten for this. This way you're able to use updated versions from the original class.