# send mails using php



## hacklinux (Oct 4, 2011)

i need to send mails using php.how do i do that?


----------



## krishnandu.sarkar (Oct 4, 2011)

A simple google search would have revealed that.

Check PHP Mail for the idea.

And for more detail check PHP: mail - Manual


----------



## hacklinux (Oct 4, 2011)

i have read all those but dat doesnt seem to work.


----------



## krishnandu.sarkar (Oct 4, 2011)

Ya, those works perfectly fine, check Spam mails, as you don't have proper header it may get into spam.


----------



## hacklinux (Oct 4, 2011)

ya checked but doesnt work...any other possibilities?


----------



## krishnandu.sarkar (Oct 4, 2011)

Are you sure..


```
<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
```

this program is not working??

It's working fine for me. Are you on Linux or using XAMPP / WAMP??


----------



## hacklinux (Oct 4, 2011)

am using wamp...and should i download any smtp server fr dat?


----------



## krishnandu.sarkar (Oct 4, 2011)

Nope, that should work fine. Don't know if there is any issue with WAMP itself.

I'd recommend to try XAMPP once if possible.

Otherwise you can use PHP Pear Mail package for SMTP Mail.


----------



## hacklinux (Oct 4, 2011)

ok...ll do dat and let u knw....

in xampp it says "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\mailf.php on line 7"
and on welcome page,der is a "status" option on right.in dat it says "SMTP service deactivated".has dis got to do anythng wid my problem?


----------



## krishnandu.sarkar (Oct 4, 2011)

Can you please post your code??

Looks like you are not trying to send mails through internet instead you are trying to send mails through your mail server. Else WTH mail() will try to find SMTP Server on localhost.


----------



## hacklinux (Oct 4, 2011)

<?php
$to = "hackpca@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "urpcissafe@gmail.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>


----------



## krishnandu.sarkar (Oct 4, 2011)

Check How to use sendmail in XAMPP for Windows | i.justrealized and try to add your mail id and password there from which you'd like to send the mail.

BTW that script has worked for me before without all these. Don't know if I'm also missing something.

Ahh figured it out I never did this from desktop. The mails scripts I've developed before was tried and tested on the server itself.

So you need to do that setting in php.ini as you need a authenticating SMTP server from which the mail will be sent. So that's must.

You can do the same in WAMP too.


----------



## hacklinux (Oct 4, 2011)

wat do i give fr smtp_server,auth_username,auth_password?


----------



## krishnandu.sarkar (Oct 4, 2011)

Yup.

10chars


----------



## hacklinux (Oct 4, 2011)

sry m nt undrstanding dat part.wat values am i supposed to give der?


----------



## Liverpool_fan (Oct 4, 2011)

Use an SMTP relay like JangoSMTP.


----------



## hacklinux (Oct 4, 2011)

ok i used.but after 4-5 mails i recieved error mails.and can i send mails to any mail id's or to oly the ones which i have added in jangosmtp?


----------



## Liverpool_fan (Oct 4, 2011)

What kind of error? 

Read this guide if it helps.
JangoMail In Progress: Technical Notes: Using the JangoMail API with PHP


----------



## hacklinux (Oct 5, 2011)

System.Exception: This From Address ("postmaster@localhost") is not
allowed to send through this account.
  at JangoEmlRelay.Relay.ProcessFile(Object o)
i get d above error as a mail from jango.


----------



## Liverpool_fan (Oct 5, 2011)

Yes of course. Use a proper From E-Mail address. Like your actual E-Mail address.


----------



## hacklinux (Oct 5, 2011)

but it worked fine wid frst 4-5 test mails....


----------



## ico (Oct 7, 2011)

lol..last time when I did this, I preferred using a MTA like exim4.


----------

