Page 1 of 1
sending mail through php
Posted: Mon Apr 06, 2009 7:19 am
by shail_csp
Hi, all
can any one suggest me, how to send mail through php.. I m using following code
$to = '
mr.shailendra.shail@gmail.com';
$subject = 'Activation link from IHTIM ';
$message = 'hello, Mr. shail<br> click here';
$headers = 'From:
IHTIM@example.com' . "\r\n" .
'Reply-To:
webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
but its giving some error, How to configure smtp or pop3 to send it.. Many Many thanks in advance..
Re: sending mail through php
Posted: Mon Apr 06, 2009 7:32 am
by Apollo
1. what happens if you leave the $headers parameter out? (just for now)
2. what error message do you get?
Re: sending mail through php
Posted: Mon Apr 06, 2009 11:56 am
by shail_csp
Apollo wrote:1. what happens if you leave the $headers parameter out? (just for now)
2. what error message do you get?
if i leave header parameter out
"sendmail_from" not set in php.ini or custom "From:" header missing in C:\wamp\www\IHTIM\Trash\sendMailTest.php on line 8
with header parameter
SMTP server response: 550 5.7.1 Unable to relay for
mr.shailendra.shail@gmail.com in C:\wamp\www\IHTIM\Trash\sendMailTest.php on line 9
Any way thank for reply.. your any suggestion is welcome..
Re: sending mail through php
Posted: Mon Apr 06, 2009 1:32 pm
by Apollo
Apparently your SMTP server is configured not to allow sending emails from random addresses such as @gmail.com. See if you can change your server's SMTP settings, or use another SMTP server.
If neither of those are possible, you could also use an alternative mail function or class, such as
PHPMailer (personally had good experience with that one, using gmail's SMTP server) or Pear or
Swift (no personal experience with the latter two, but heard good things about 'em).
Re: sending mail through php
Posted: Mon Apr 06, 2009 1:50 pm
by shail_csp
Apollo wrote:Apparently your SMTP server is configured not to allow sending emails from random addresses such as @gmail.com. See if you can change your server's SMTP settings, or use another SMTP server.
If neither of those are possible, you could also use an alternative mail function or class, such as
PHPMailer (personally had good experience with that one, using gmail's SMTP server) or Pear or
Swift (no personal experience with the latter two, but heard good things about 'em).
can you give me a small example(code) so that i can get more help.. Many many thanks..
Re: sending mail through php
Posted: Mon Apr 06, 2009 1:55 pm
by shail_csp
Apollo wrote:Apparently your SMTP server is configured not to allow sending emails from random addresses such as @gmail.com. See if you can change your server's SMTP settings, or use another SMTP server.
If neither of those are possible, you could also use an alternative mail function or class, such as
PHPMailer (personally had good experience with that one, using gmail's SMTP server) or Pear or
Swift (no personal experience with the latter two, but heard good things about 'em).
how to configure gmail's SMTP. If you have any idea..!!!
Re: sending mail through php
Posted: Mon Apr 06, 2009 3:19 pm
by Apollo
shail_csp wrote:can you give me a small example(code) so that i can get more help.. Many many thanks..
Using the phpmailer class:
Code: Select all
require_once('class.phpmailer.php');
$msg = new PHPMailer();
$msg->IsSMTP();
$msg->Host = "ssl://smtp.gmail.com:465";
$msg->SMTPAuth = true;
$msg->Username = 'gmail_username';
$msg->Password = 'gmail_password';
$msg->From = 'john@example.com';
$msg->FromName = 'John Doe';
$msg->AddAddress('cindy@somewhere.com');
$msg->Subject = 'Testing';
$msg->Body = 'Hello there';
$msg->Sender = $msg->From; // for Return-path
if (!$msg->Send()) die('epic fail...');
shail_csp wrote:how to configure gmail's SMTP. If you have any idea..!!!
In your server's PHP configuration is an 'SMTP' value. But you can ignore that if you use the example from above.
Re: sending mail through php
Posted: Mon Apr 06, 2009 4:11 pm
by shail_csp
Apollo wrote:shail_csp wrote:can you give me a small example(code) so that i can get more help.. Many many thanks..
Using the phpmailer class:
Code: Select all
require_once('class.phpmailer.php');
$msg = new PHPMailer();
$msg->IsSMTP();
$msg->Host = "ssl://smtp.gmail.com:465";
$msg->SMTPAuth = true;
$msg->Username = 'gmail_username';
$msg->Password = 'gmail_password';
$msg->From = 'john@example.com';
$msg->FromName = 'John Doe';
$msg->AddAddress('cindy@somewhere.com');
$msg->Subject = 'Testing';
$msg->Body = 'Hello there';
$msg->Sender = $msg->From; // for Return-path
if (!$msg->Send()) die('epic fail...');
shail_csp wrote:how to configure gmail's SMTP. If you have any idea..!!!
In your server's PHP configuration is an 'SMTP' value. But you can ignore that if you use the example from above.
Wow it Cool, Thanks.. U r really master of php..
Is there any way to send sms to any mobile.. through php. Basically I have to send the result message if some one is sending his roll number to my account/number.. How to detect that msg or number and responce to same.. If you have any idea.. !!!!!!
Re: sending mail through php
Posted: Mon Apr 06, 2009 6:07 pm
by Apollo
shail_csp wrote:Is there any way to send sms to any mobile.. through php.
No idea really, never done anything with SMS. But you better open a new topic for that, as it's pretty unrelated, and put "SMS" in the title to draw people's attention who may be into this sort of thing.