/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] How to send email with PHP?

guys..i am running my website on the local host(my own PC)……
and i am trying to send mail to my yahoo acc..

i have try the below code ..but it is not working…..

<?php
$to = “[email protected]“;
$subject = “Hi!”;
$body = “Hi,nnHow are you?”;
$head = “From:[email protected]“;

$mailsent = mail($to, $subject, $body, $head);
if ($mailsent) {
echo “<p>Message successfully sent!</p>”;
} else {
echo “<p>Message delivery failed…</p>”;
}

?>

this is my php.ini configuration…

[mail function]
; For Win32 only.
SMTP = pop3hot.com
smtp_port = 25

; For Win32 only.
sendmail_from = [email][email protected][/email]

does anyone know what is wrong with my code or my configuration??pls tell me..cause i have tried to search for many source but still cant to get the code to run………!!!!!!!!
thanks alot!!!!!!!!!!!!!!!

to post a comment
PHP

25 Comments(s)

Copy linkTweet thisAlerts:
@purefanJul 25.2006 — What error are you getting??

if you are not getting any error then try looking for the junk folder. To improve delivery you might need to add some headers, check php.net/mail there I found some useful headers, doesnt assure a perfect deliver but it does improve it
Copy linkTweet thisAlerts:
@dethlonauthorJul 25.2006 — dear purefan;

the page always echo "Message delivery failed...". which means the mail fuction return false value....(not working)!!!...

i guess there may be some configuration problems..but i dunno what...do u have any idea on this??

thanks..
Copy linkTweet thisAlerts:
@john_de116Jul 25.2006 — Hi,

$head="From: [email][email protected][/email]";

Give the space betwen From: and mail_id. Defenetely, mail will sent.

Check it.
Copy linkTweet thisAlerts:
@dethlonauthorJul 25.2006 — dear john;

i have tried to give space to it..but...same thing happends...it still echo "Message delivery failed...". i think its about config problems....do u know how to set the smtp conn to allow email run on local host??
Copy linkTweet thisAlerts:
@NogDogJul 25.2006 — I've had success sending SMPT mail (both from my WinXP PC and from a Windows Server host) by using the [url=http://phpmailer.sourceforge.net/]PHPMailer class[/url], which includes a SMTP class with it.
Copy linkTweet thisAlerts:
@dethlonauthorJul 26.2006 — dear nogdog;

i have read the article about the PHP mailer and the installation instruction is as below :

Copy class.phpmailer.php into your php.ini include_path. If you are using the SMTP mailer then place class.smtp.php in your path as well. If you do not have control of the include directory and you are running PHP 4.0 or higher you can use this function to set it to the correct directory:

ini_set("include_path", ".:/path/to/phpmailer/dir");

Or this:

$mail->PluginDir = "/path/to/phpmailer/dir";

[/QUOTE]


actually i dont really understand what it ask for. so, how actually should I configure my PHP.ini file, i mean the include_path part....

the default one is :

Windows: "path1;path2"

include_path = ".;c:phpincludes"

should it become like this? :

Windows: "path1;path2"

include_path = ".C:Program FilesApache GroupApachehtdocsphpmailer"

(the PHP mailer folder contains the class.phpmailer.php and class.smtp.php in it)

or? can u explain abit on this config??thanks....

my mailing code:

<?

require_once "class.phpmailer.php";

$mail = new phpmailer();

$mail->IsSMTP();

$mail->Host = "pop3hot.com"; // verify that this is correct host

$mail->Port = 25; // verify that this is correct port on mail host

$mail->Username = "[email protected]"; // your login name on the mail host

$mail->Password = "XXXXXXXXX"; // your password on the mail host

$mail->From = "[email protected]";

$mail->FromName = "Administrator";

$mail->AddAddress("[email protected]");

$mail->Subject = "Password Retrieval";

$mail->Body = "Password is: abcdefg";

$result = $mail->Send();

if($result)

{

echo "success";

}

else

{

echo "failed";

}

?>
Copy linkTweet thisAlerts:
@NogDogJul 26.2006 — The include path should include whatever directory you have the PHPMailer files in: either save them to a directory that's already in your include path, or else add their directory to your include path in php.ini. Most default settings have the current directory (".") as the first directory in the include path, so the other option is to just copy the files to the same directory as the script that will call them, if you don't want to mess around with changing the settings right now.
Copy linkTweet thisAlerts:
@dethlonauthorJul 26.2006 — ok..now my php.ini default setting is :

Windows: "path1;path2"

include_path = ".;c:phpincludes"


and what i do is just to create the "includes" folder in the "c:php". then i copied the class.phpmailer.php and class.smtp.php into the "includes" folder....and it still dont works!!!.....

do u have any solution on this???
Copy linkTweet thisAlerts:
@NogDogJul 26.2006 — No ideas without knowing what errors you're getting.
Copy linkTweet thisAlerts:
@dethlonauthorJul 26.2006 — i just dont display any errors....it just displayed/echoed "failed"...by the way ..can we catch what errors have been occur??
Copy linkTweet thisAlerts:
@NogDogJul 26.2006 — The last error message will be in [b]$mail->ErrorInfo[/b] (where "$mail" is whatever name you used to instantiate the phpmailer class).
Copy linkTweet thisAlerts:
@dethlonauthorJul 26.2006 — Mailer Error: SMTP Error: The following recipients failed: [email][email protected][/email]

this is the errors....
Copy linkTweet thisAlerts:
@NogDogJul 26.2006 — Try modifying the SetError method in the phpmailer class to the following:
[code=php]
function SetError($msg) {
$this->error_count++;
$this->ErrorInfo = $msg;
user_error($msg, E_USER_WARNING); // this is the change
}
[/code]

At the start of your main script, do a [b]error_reporting(E_ALL);[/b] so that all errors and warnings get reported.
Copy linkTweet thisAlerts:
@dethlonauthorJul 26.2006 — it keep saying~SMTP errors!!!!!! any other approach other than using PHP mailer?
Copy linkTweet thisAlerts:
@aussie_girlJul 26.2006 — [mail function]

; For Win32 only.

SMTP = pop3hot.com<--This is just a website not a web server..

smtp_port = 25
Copy linkTweet thisAlerts:
@dethlonauthorJul 26.2006 — so...is there any webserver i can used to send email???????? i am running the code in localhost environment.......
Copy linkTweet thisAlerts:
@aussie_girlJul 26.2006 — so...is there any webserver i can used to send email???????? i am running the code in localhost environment.......[/QUOTE]

Well there is this one, I 've never used it...

http://www.qksoft.com/qk-smtp-server/index.html
Copy linkTweet thisAlerts:
@dethlonauthorJul 27.2006 — guys...

i have try the php mailer and it works with the pop3hot.com (smtp server)...but it only work for a while(several times).....after a while i turn back not working.....just wanna ask ...is there any limit to access to cetain smtp server?? for example,is that i can only use it for certain numbers or whatever???
Copy linkTweet thisAlerts:
@NogDogJul 27.2006 — I suppose it's possible, but you'd have to ask them (or look for a "terms of use", FAQ, etc. on their site that tells you).
Copy linkTweet thisAlerts:
@dethlonauthorJul 27.2006 — ok thanks NogDog and also aussie girl...i undestand the cause already....they block me as i sent to many mails in one time (spamming)....i try to use my other account n it works....thanks again~~

thanks for all the help~~~
Copy linkTweet thisAlerts:
@beginnerzAug 09.2006 — Message was not sentMailer Error: Language string failed to load: recipients_failed

What is this error message suppose to mean?

my code is here:
[code=php]
<?php
require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "pop3hot.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "sample"; // SMTP password

$mail->From = "[email protected]";
$mail->FromName = "Mailer";
$mail->AddAddress("[email protected]");

$mail->Subject = "first mailing";
$mail->Body = "hi ! nn this is First mailing I made myself with PHPMailer !";
$mail->WordWrap = 50;

if(!$mail->Send())
{
echo "Message was not sent";
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}

?>
[/code]
Copy linkTweet thisAlerts:
@dethlonauthorAug 09.2006 — to use the pop3hot.com smtp server u must use ur existing hotmail account together with your password....try to use real data instead of all sample stuff...
Copy linkTweet thisAlerts:
@beginnerzAug 09.2006 — yes, i m using real hotmail account. Is it i am doing a wrong installation with phpmailer? because i m directly put the phpmailer in my system folder, and directly require it like - require("phpmailer/class.phpmailer.php"); from the phpmailer folder.
Copy linkTweet thisAlerts:
@dethlonauthorAug 09.2006 — ya u need to put the class.phpmailer.php and class.smtp.php in your system and also in the php include path...(u need to configure your php.ini file to include these 2 files in php include path).

this is my working code:

<?

require_once "class.phpmailer.php";

$mail = new phpmailer();

$mail->IsSMTP();

$mail->Host = "pop3hot.com"; // verify that this is correct host

$mail->Port = 25; // verify that this is correct port on mail host

$mail->Username = "[email protected]"; // your login name on the mail host

$mail->Password = "abc"; // your password on the mail host

$mail->From = "[email protected]";

$mail->AddReplyTo("[email protected]","Administrator");

$mail->FromName = "Administrator";

$mail->AddAddress("$email","$username");

$mail->Subject = "PHP Chatting Password Retrieval";

$mail->WordWrap = 100;

$mail->IsHTML(true);

$mail->Body = "Your Password is: $user_password.<br>

Please remmember to write it down and keep it in a secret place...<br>

For Further Assistance and Enquiries, Please Contact Our Administrator!!!.</br>

Thanks you";

$mailsent = $mail->Send();

?>
Copy linkTweet thisAlerts:
@dethlonauthorAug 09.2006 — set ur php.ini path become like this :

Windows: "path1;path2"

include_path = ".;c:/php/includes"

then create an 'includes' folder inside ur c?HP and put the 2 files in it...
×

Success!

Help @dethlon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...