sending email from PHP website

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 6848 Views - Last Post: 19 February 2012 - 12:24 PM Rate Topic: -----

#1 praveenphp  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 18-February 12

sending email from PHP website

Posted 18 February 2012 - 01:01 PM

I am trying to send a mail to gmail from XAMPP. But i am getting message sent successfully. BUt messages are not delivering to my inbox.

php.ini code
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 587

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = praveenk60@gmail.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"





sendmail.ini code
# Mercury
#account Mercury
#host localhost
#from postmaster@localhost
#auth off
# A freemail service example
#account Hotmail
#tls on
#tls_certcheck off
#host smtp.live.com
#from [exampleuser]@hotmail.com
#auth on
#user [exampleuser]@hotmail.com
#password [examplepassword]


account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from praveenkd1@gmail.com
auth on
user praveenk60@gmail.com
password **********

account default : Gmail

port=58



My PHP Code is as follows
<?php
$to = "praveenk@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("Message successfully sent!");
} else {
echo("Message delivery failed");
}

?>



Please help me.
Thanks in advance

This post has been edited by Jstall: 18 February 2012 - 01:13 PM
Reason for edit:: Added code tags, when posting code please use [ code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: sending email from PHP website

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2990
  • Posts: 10,329
  • Joined: 08-August 08

Re: sending email from PHP website

Posted 18 February 2012 - 01:14 PM

Please use code tags in the future.
PHP can only send to the mail server. It cannot guarantee that the message is delivered.
Was This Post Helpful? 0
  • +
  • -

#3 praveenphp  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 18-February 12

Re: sending email from PHP website

Posted 18 February 2012 - 01:28 PM

View PostCTphpnwb, on 18 February 2012 - 01:14 PM, said:

Please use code tags in the future.
PHP can only send to the mail server. It cannot guarantee that the message is delivered.



Is there any problem in my code.. Actually i deleted all the previous code in sendmail.ini and php.ini files and pasted the code which is given in my post.....


SO asking... is that old code is necessary or it is fine??

thanks and regards
praveen
Was This Post Helpful? 0
  • +
  • -

#4 praveenphp  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 18-February 12

Re: sending email from PHP website

Posted 18 February 2012 - 01:46 PM

Please any one help me... It is little bit urgent and answer me...


Thanks in advance for all
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2990
  • Posts: 10,329
  • Joined: 08-August 08

Re: sending email from PHP website

Posted 18 February 2012 - 01:56 PM

It should work. Do you have a mail server set up?
Was This Post Helpful? 0
  • +
  • -

#6 praveenphp  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 18-February 12

Re: sending email from PHP website

Posted 18 February 2012 - 02:02 PM

View PostCTphpnwb, on 18 February 2012 - 01:56 PM, said:

It should work. Do you have a mail server set up?


Thank u very much for ur kind reply.....
Sorry as i already told i am new to development.. So i dont know about mail server set up. Please can u suggest me what is mail server setup and how i need to set up it??

Once again thank u very much
Was This Post Helpful? 0
  • +
  • -

#7 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: sending email from PHP website

Posted 18 February 2012 - 04:50 PM

If you're willing to try PHPMailer, it can be used to send emails via your Gmail's SMTP server even without you having a mail server installed on your machine.
Link: Sending e-mails via SMTP with PHPmailer and GMail

If not then check out hMailServer.

This post has been edited by codeprada: 18 February 2012 - 04:53 PM

Was This Post Helpful? 0
  • +
  • -

#8 praveenphp  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 18-February 12

Re: sending email from PHP website

Posted 19 February 2012 - 12:16 AM

Thank u very much codeprada

Please can u explain me detailed steps.... I want send a email from xapp (php) application to my gamil account...

beofre hosting website.. i want check my self...
Was This Post Helpful? -1
  • +
  • -

#9 praveenphp  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 18-February 12

Re: sending email from PHP website

Posted 19 February 2012 - 06:50 AM

Hi..........

Please any one help me. Is it possible to send email fro gmail account from XAMPP. In home I am developing a website. But I fed up by trying. I am very new to PHP application. So please any one help me is it possible to send a mail to gmail account in my local system?

It is little bit urgent.... Please help me....

Thanks in advance
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5313
  • View blog
  • Posts: 27,216
  • Joined: 10-May 07

Re: sending email from PHP website

Posted 19 February 2012 - 06:58 AM

View Postpraveenphp, on 19 February 2012 - 08:50 AM, said:

Is it possible to send email fro gmail account from XAMPP.

Yes.

View Postpraveenphp, on 19 February 2012 - 08:50 AM, said:

But I fed up by trying.

Helping you is impossible without being able to see your code.
Was This Post Helpful? 0
  • +
  • -

#11 praveenphp  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 18-February 12

Re: sending email from PHP website

Posted 19 February 2012 - 08:05 AM

<?php
require_once('PHPMailer_5.2.1\class.phpmailer.php');
 
$mail             = new PHPMailer();
 
$body             = "Welcome";

 
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth   = true;                  		// enable SMTP authentication
$mail->SMTPSecure = "ssl";                 		// sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      		// sets GMAIL as the SMTP server
$mail->Port       = 465;                  	 	// set the SMTP port for the GMAIL server
$mail->Username   = "php@gmail.com";  	// GMAIL username
$mail->Password   = "********";		// GMAIL password
 
$mail->SetFrom('from@gmail.com', 'First Last');
 
$mail->Subject    = "Test PHPMailer via Gmail smtp";
 
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
 
$mail->MsgHTML($body);
 
$address = "receiver@gmail.com";
$mail->AddAddress($address, "To Name");
 
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>




Please help me man.. Presently I am doing code for this....

This post has been edited by no2pencil: 19 February 2012 - 08:10 AM
Reason for edit:: Corrected code tags

Was This Post Helpful? 0
  • +
  • -

#12 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: sending email from PHP website

Posted 19 February 2012 - 09:13 AM

You must allow outgoing connections via port 465. If that's not already done have a look at this guide:
Open A Port In Windows Firewall

If that doesn't work then set the SMTPDebug property of PHPMailer to true and view the errors.

This post has been edited by codeprada: 19 February 2012 - 09:13 AM

Was This Post Helpful? 0
  • +
  • -

#13 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: sending email from PHP website

Posted 19 February 2012 - 09:16 AM

The steps are in the documentation, assuming you're referring to hMailServer.
Was This Post Helpful? 0
  • +
  • -

#14 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5313
  • View blog
  • Posts: 27,216
  • Joined: 10-May 07

Re: sending email from PHP website

Posted 19 February 2012 - 09:27 AM

** Duplicate topics merged **

Please avoid opening the same topic, asking the same question, about the same code. It doesn't get your question answered any faster.
Was This Post Helpful? 0
  • +
  • -

#15 praveenphp  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 18-February 12

Re: sending email from PHP website

Posted 19 February 2012 - 10:56 AM

Hi Codeparad...

I added port and did as u said..

But i am getting following error.
Mailer Error: The following From address failed: from@gmail.com

for the following code.
<?php
require_once('PHPMailer_5.2.1\class.phpmailer.php');
 
$mail             = new PHPMailer();
 
$body             = "Welcome";



$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth   = true;                  		// enable SMTP authentication
$mail->SMTPSecure = "ssl";                 		// sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      		// sets GMAIL as the SMTP server
$mail->Port       = 465;                  	 	// set the SMTP port for the GMAIL server
$mail->Username   = "praveenk60@gmail.com";  	// GMAIL username
$mail->Password   = "*******";		// GMAIL password
 
$mail->SetFrom('praveenk60@gmail.com', 'First Last');
 
$mail->Subject    = "Test PHPMailer via Gmail smtp";
 
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
 
$mail->MsgHTML($body);
 
$address = "nagarajbvcvr@gmail.com";
$mail->AddAddress($address, "To Name");
 
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>



View Postno2pencil, on 19 February 2012 - 09:27 AM, said:

** Duplicate topics merged **

Please avoid opening the same topic, asking the same question, about the same code. It doesn't get your question answered any faster.



I am sorry...
Because i need urgent solution.. so man.... anyway sorry..

This post has been edited by no2pencil: 19 February 2012 - 10:58 AM
Reason for edit:: Corrected code tags

Was This Post Helpful? -1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2