Jump to content
xisto Community
Sign in to follow this  
itssami

How To Enable Mail() Function In Php

Recommended Posts

im just trying to send mail by using a very simple php function mail() but it is not working.the format is


$to = "email@example.com";$subject = "Hi!";$body = "Hi,\n\nHow are you?";if (mail($to, $subject, $body)) {  echo("<p>Message successfully sent!</p>"); } else {  echo("<p>Message delivery failed...</p>"); }



I think there is something wrong with php.ini setting..maybe something to do with SMTP settings.. i want to send email FROM either hotmail , gmail , or yahoo or any other web based email because i dont know my ISP smtp setting..so can anyone please help me , where to make change and what to make change ?

Notice from BuffaloHELP:
All codes must be used inside of CODE bbcode tag.

Share this post


Link to post
Share on other sites

im just trying to send mail by using a very simple php function mail() but it is not working.the format is $to = "email@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
I think there is something wrong with php.ini setting..maybe something to do with SMTP settings.. i want to send email FROM either hotmail , gmail , or yahoo or any other web based email because i dont know my ISP smtp setting..so can anyone please help me , where to make change and what to make change ?


I've used the mail function quite alot on external hosts and its worked fine. When i tried to run this script on my localhost i got an error saying i needed to configure my php.ini settings for the FROM address but im not confident with playing with .ini settings and such so i left that be.

If you want to send an email and have the FROM address be anything specific you an use the headers variable in the mail() function.

eg:

$headers = FROMaddress@whatever.com;mail($to, $subject, $body, $headers);


now when the mail is received the from address will be FROMaddress@whatever.com. The only problem is if sending to a hotmail user, or possibly some other email accounts, but particularly in hotmail the email provider will notcie the diferene in domains, eg sending the email from subdomain.trap17.com but having the FROM address as me@host.com hotmail will notice the differences and alert the user that the sender cannot be verified. If however your website was me.myhost and the FROM address was notme@myhost there would be no problem. I hope that helped with changing the FROM address. Sorry I cant help much about the problem with it not working though.

NOTE: it seems by editing this line

; For Win32 only.;sendmail_from = me@example.com

in your .ini file you can permanently set the FROM address without using the $headers method. :angry: Although i suspect this will still have the problems with verifying the sender's ID.

EDIT: Is there an error display when you try to use the mail function that is outputted to the browser? if there is could you post it and maybe it will help someone to see whats going on. :angry:
Edited by shadowx (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.