DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

PHP Mail function

By: | 24 Aug 2009 2:25 pm

Hello

I want to send a mail in local host using through PHP but I can`t send it ..Please suggest me how to send a mail using PHP.
Warning: mail() [function.mail]: SMTP server
response: 550 The address is not valid. in
C:xampphtdocstest1send_contact.php on line 11
ERROR

here I`m sending you php code ..

Mail.html
<form name="form1" method="post" action="send_contact.php">

subject:<input name="subject" type="text" id="subject" size="50"><br/>
</br>
Detail:<textarea name="detail" cols="50" rows="4" id="detail"></textarea><br/>

</br>
Name:<input name="name" type="text" id="name" size="50"><br/>
Mail:<input name="customer_mail" type="text" id="customer_mail" size="50"><br/>

</br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">

</form>
send_contact.php:
<?php
// subject
$subject ="$subject";
// Details
$message="$detail";
// sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";
$to =`karthick_cse06@...`;
$send_contact=mail($to,$subject,$message,$header);
if($send_contact){
echo "We`ve recived your contact information";
}
else {
echo "ERROR";
}
?>

Comments

Sending PHP email from Windows servers is often problematic. Unike Unix and Linux systems, most Windows systems don`t have an SMTP server for PHP to use.  It is often necessary to edit the php.ini file and set an external SMTP server.  After any change to php.ini, restart the webserver program for the changes to take effect.

Perhaps you have that part set up correctly. To find out, you should make the most basic test possible, someting on the order of:

mail("karthick_cse06@...", "test message", "this is a test");

See if this line (in PHP tags) when run through the webserver will transmit an email to your account. Watch the spam folder.

Two other areas which could cause problems in your implementation are the From: address. From: addresses often don`t work as well on Windows as they do from Unix systems. Hence, your ability to set them at all may be limited. The usage of "real name" <email@...> for the address may also fail in some cases.

One thing to keep in mind is that the From: address is set up in an email header value in the fourth argument of the mail() function. You can pass almost anything in that variable but whether it will be interpreted by the SMTP server is the potential issue. For standards-compliant servers you have to follow the expected spelling, capitalization, format and line ending for the header. In this case, it should be:

$header = "From: email@...rn";

Note that "From" is capitalized and there is one space after the colon. The rn is a representation of the carriage return (ASCII 13) and newline (ASCII 10) characters which are part of the standard for line endings on email. They will work in double quotes but not single quotes.

Your example script should not be used on the web since it is fairly easily hacked and could be used to send spam email from your domain/IP and quickly get your machine on a blacklist. For one thing you are doing no input validation of the form variables being passed to the mail() function.

By: | 24 Aug 2009

To learn PHP try these websites:

http://www.tizag.com/phpT/ - An easy introduction
http://www.w3schools.com/php/ - More in depth coverage

http://www.php.net/ - Complicated, I use it mostly for reference

By: | 24 Aug 2009

This error means that the mail server is not accepting the format of the email address. I believe it could be the email address you`re sending to, sending from, or using for authorization.

What I would suggest doing is to echo the $to and $header variables so you can make sure that they are properly formatted. Also, check to see if you need to use an email address, rather than just a user name, for SMTP auth, particularly if you`re sending via a mail server on a different box.

By: | 24 Aug 2009

I had this exact same problem with php`s mail() under debian. I could send to my private email but not to my yahoo email. I believe yahoo is analyzing the headers and figure out that you are sending via php, so they block it.

I get much better luck using an smtp class. With an smtp class you are actually sending it out through a mail server of your choice instead of trying to create your own.
Check this one out: http://www.phpclasses.org/browse/package/3029.html

By: | 24 Aug 2009

I believe that is backwards. When you use the mail() function, it is my understanding that it is connecting to your own SMTP server (or one that you are authorized to use) to deliver the mail. Hence the need to specify a server in the php.ini file.

When you use an SMTP class, they are typically using a socket connection directly to the recipient`s mail server. This makes it easier to do things like sending HTML email or including attachments.

that said, unless you`re doing this to learn php, I agree that an SMTP class such as the one, is a much more efficient way to do it.

By: | 24 Aug 2009

Hello

I have used windows OS and Xampp control .. But I can`t send a mail to my yahoo ID .I got a problem with PHP’s mail() , which was not sending any email messages out.I`m sending you my php coding. If you see any problem or any mistake in my code then plz tell me and suggest me how i can send

And I did some changes in sendmail.ini
[sendmail]

; you must change mail.mydomain.com to your smtp server,
smtp_server=mail.mydomain.com

; smtp port (normally 25)

smtp_port=25

; if your smtp server requires authentication, modify the following two
lines

auth_username=username
auth_password=drowssap

; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines

pop3_server=mail.mydomain.com
pop3_username=username
pop3_password=drowssap

my code is here
<snip>

Warning: mail() [function.mail]: SMTP
server response: 550 The address is not valid. in
C:xampphtdocstest2send_contact.php on line 12
ERROR
--------------------------------------

email servers do a lot of checking before they are willing to receive email so using a php class that does NOT cache e-mail is not a good idea.

Some servers will always respond to a new IP with `service temporarily unavailable so without a cache then email will fail.

Apart from black/white/grey IP lists, many email servers will also check a SPF record that is associated with a domain in the zone file.

If your using a development environment then your best off just using some external SMTP server. The problems you will have here are - Some ISP`s block port 25 so you have to use port 26 Some servers require pop before SMTP authentication Some server will reject php`s default mail headers so you have to change them with the header() function.

By: | 24 Aug 2009

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move