This topic is locked
[SOLVED]

 send mail by local server

2/7/2012 6:06:07 AM
PHPRunner General questions
W
wundebar author

Hi to everybody.

I'm trying to send email from my database after that a new record is added or modified.

The Server run on XAMPP and pc are connected by intranet but we have also internet <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=18982&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />

I've used the pre-compiled script of phprunner but it not works, it give me many errors.

I found this topic here, http://www.asprunner.com/forums/topic/14310-mail-functionmail-smtp-server-response-550-must-be-authenticated/ where i've read about PHPMailer.

This is the code that i've inserted into "after record added" and "after record updated" in "events page":



require_once('C:\xampp\htdocs\PHPMailer\class.phpmailer.php');

require_once('C:\xampp\htdocs\PHPMailer\class.smtp.php');

//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP

$mail->Host = "smtp.rivisrl.it"; // SMTP server
$mail->SMTPAuth = true; // enable SMTP authentication

$mail->Host = "smtp.rivisrl.it"; // sets the SMTP server

$mail->Port = 25;

$mail->Username = "xxxxxx@rivisrl.it"; // SMTP account username

$mail->Password = "xxxxx"; // SMTP account password
$mail->SetFrom('xxxxxxx@rivisrl.it', 'prova1 prova2');
$mail->Subject = "something..";
$address = "xxxxxx@rivisrl.it";

$mail->AddAddress($address, "prova database");
if(!$mail->Send()) {

echo "Mailer Error: " . $mail->ErrorInfo;

} else {

echo "Message sent!";
$mail->SmtpClose();

unset($mail);

}


The required files are into the root of xampp as you can see.

When i add or modify a record on database there are not errors yet but i don't recieve any mail to my personal account..

where i make mistake?

I have to copy just "class.phopmailer.php" and "class.smtp.php" into the root of xampp?

Please help me <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=18982&image=2&table=forumtopics' class='bbc_emoticon' alt=':(' />

Thanks!

W
wundebar author 2/7/2012



Check this article: http://roshanbh.com.np/2007/12/sending-e-mail-from-localhost-in-php-in-windows-environment.html


Hi cristian,

i have already set my php.ini file, that's how it figure now :



[mail function]

; For Win32 only.

SMTP = smtp.rivisrl.it

smtp_port = 25
; For Win32 only.

http://php.net/sendmail-from

sendmail_from = xxxxxx@rivisrl.it


so i've deleted previous code and i've write this into "page events" : mail("xxxxxxx@rivisrl.it","test subject","test body");
so after re-build of phprunner i get this error into the database: mail() [function.mail]: SMTP server response: 553 sorry, you need to supply the correct username and password for SMTP-AUTH (#5.7.1)
The link that you paste don't talk about autentication error..
edit..

i've just tried also this code



function setSMTP($server , $senderMail, $port = 25)

{
ini_set('SMTP' , $server);
ini_set('smtp_port' , $port);
ini_set('sendmail_from' , $senderMail);

}
setSMTP('smtp.rivisrl.it', 'xxxxxxxx@rivisrl.it');
$to = "xxxxxxx@rivisrl.it";

$subject = "E-mail inviata dallo scadenzario";

$message ="prova.. ";
$sentOK = mail($to, $subject, $message);

echo "sentOK=" . $sentOK;


and it give me the same error... i really don't know how to solve the problem.

W
wundebar author 2/7/2012



Hi cristian,

i have already set my php.ini file, that's how it figure now :



[mail function]

; For Win32 only.

SMTP = smtp.rivisrl.it

smtp_port = 25
; For Win32 only.

http://php.net/sendmail-from

sendmail_from = xxxxxx@rivisrl.it


so i've deleted previous code and i've write this into "page events" : mail("xxxxxxx@rivisrl.it","test subject","test body");
so after re-build of phprunner i get this error into the database: mail() [function.mail]: SMTP server response: 553 sorry, you need to supply the correct username and password for SMTP-AUTH (#5.7.1)
The link that you paste don't talk about autentication error..
edit..

i've just tried also this code



function setSMTP($server , $senderMail, $port = 25)

{
ini_set('SMTP' , $server);
ini_set('smtp_port' , $port);
ini_set('sendmail_from' , $senderMail);

}
setSMTP('smtp.rivisrl.it', 'xxxxxxxx@rivisrl.it');
$to = "xxxxxxx@rivisrl.it";

$subject = "E-mail inviata dallo scadenzario";

$message ="prova.. ";
$sentOK = mail($to, $subject, $message);

echo "sentOK=" . $sentOK;


and it give me the same error... i really don't know how to solve the problem.


Ok i've solved the first problem, <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=64180&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> i make a little mistake.. anyway i would like to know if is possible send the mail with a specific drop down box name.
I try to be more clear, i have a drop down box with several names like: Mario, giorgio, luca.. so i would like send a mail to the luca's account only if i select "luca" in the dropdown box. It is possible?

Thanks for help

Admin 2/7/2012

Sure, you can display a dropdown box with email addresses and send an email to selected user. The actual code depends on what page and event you need to send email from. Assuming that dropdown box name is "email" you can access the value of that dropdown box as $values["email"] in events like BeforeAdd or BeforeEdit.

W
wundebar author 2/8/2012



Sure, you can display a dropdown box with email addresses and send an email to selected user. The actual code depends on what page and event you need to send email from. Assuming that dropdown box name is "email" you can access the value of that dropdown box as $values["email"] in events like BeforeAdd or BeforeEdit.


Hi Sergey,

i'm not so expert with php, anyway i've modified my code in this way


error_reporting(E_STRICT);
date_default_timezone_set('Europe/Rome');
require_once('C:\xampp\htdocs\PHPMailer\class.phpmailer.php');
$mail = new PHPMailer();
$body = file_get_contents('C:\xampp\htdocs\PHPMailer\corpo.txt');

$body = str_replace("[\]",'',$body);
$mail->IsSMTP();

$mail->Host = "smtp.rivisrl.it";

$mail->SMTPDebug = 1;





$mail->SMTPAuth = true;

$mail->Host = "smtp.rivisrl.it";

$mail->Port = 25;

$mail->Username = "xxxxxx/rivisrl.it";

$mail->Password = "xxxxxx";
$mail->SetFrom('xxxxxxx@rivisrl.it', 'Database');
$mail->Subject = "Nuovo record aggiunto nel Database";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$address1 = "xxxxx1@rivisrl.it";

$address2 = "xxxxx2@rivisrl.it";
$mail->AddAttachment("C:\xampp\htdocs\PHPMailer\examples\images\phpmailer.gif");

$mail->AddAttachment("C:\xampp\htdocs\PHPMailer\examples\images\phpmailer_mini.gif");
if ($values["Referente interno"]=="Luca")

{

$mail->Addaddress($address1);

}

elseif

($values["Referente interno"]=="Giorgio")

{

$mail->Addaddress($address2);

}


The Field name of dropdown box is "Referente interno" and the list of values are names like Luca, Giorgio, etc...

With this code the database don't gave to me any error, but don't arrive any mail to my personal account.

Maybe i'm making some error, but i don't know which kind of error.. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=64205&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

C
cgphp 2/8/2012
error_reporting(E_STRICT);
date_default_timezone_set('Europe/Rome');
require_once('C:\xampp\htdocs\PHPMailer\class.phpmailer.php');
$mail = new PHPMailer();
$body = file_get_contents('C:\xampp\htdocs\PHPMailer\corpo.txt');

$body = str_replace("[\]",'',$body);
$mail->IsSMTP();

$mail->Host = "smtp.rivisrl.it";

$mail->SMTPDebug = 1;





$mail->SMTPAuth = true;

$mail->Host = "smtp.rivisrl.it";

$mail->Port = 25;

$mail->Username = "xxxxxx/rivisrl.it";

$mail->Password = "xxxxxx";
$mail->SetFrom('xxxxxxx@rivisrl.it', 'Database');
$mail->Subject = "Nuovo record aggiunto nel Database";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->Body = $body;
$address1 = "xxxxx1@rivisrl.it";

$address2 = "xxxxx2@rivisrl.it";
$mail->AddAttachment("C:\xampp\htdocs\PHPMailer\examples\images\phpmailer.gif");

$mail->AddAttachment("C:\xampp\htdocs\PHPMailer\examples\images\phpmailer_mini.gif");
if($values["Referente interno"]=="Luca")

{

$mail->AddAddress($address1);

}

elseif($values["Referente interno"]=="Giorgio")

{

$mail->AddAddress($address2);

}
if(!$mail->Send()) {

echo 'Message was not sent.';

echo 'Mailer error: ' . $mail->ErrorInfo;

} else {

echo 'Message has been sent.';

}
W
wundebar author 2/8/2012


error_reporting(E_STRICT);
date_default_timezone_set('Europe/Rome');
require_once('C:\xampp\htdocs\PHPMailer\class.phpmailer.php');
$mail = new PHPMailer();
$body = file_get_contents('C:\xampp\htdocs\PHPMailer\corpo.txt');

$body = str_replace("[\]",'',$body);
$mail->IsSMTP();

$mail->Host = "smtp.rivisrl.it";

$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;

$mail->Host = "smtp.rivisrl.it";

$mail->Port = 25;

$mail->Username = "xxxxxx/rivisrl.it";

$mail->Password = "xxxxxx";
$mail->SetFrom('xxxxxxx@rivisrl.it', 'Database');
$mail->Subject = "Nuovo record aggiunto nel Database";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->Body = $body;
$address1 = "xxxxx1@rivisrl.it";

$address2 = "xxxxx2@rivisrl.it";
$mail->AddAttachment("C:\xampp\htdocs\PHPMailer\examples\images\phpmailer.gif");

$mail->AddAttachment("C:\xampp\htdocs\PHPMailer\examples\images\phpmailer_mini.gif");
if($values["Referente interno"]=="Luca")

{

$mail->AddAddress($address1);

}

elseif($values["Referente interno"]=="Giorgio")

{

$mail->AddAddress($address2);

}
if(!$mail->Send()) {

echo 'Message was not sent.';

echo 'Mailer error: ' . $mail->ErrorInfo;

} else {

echo 'Message has been sent.';

}



It Works! i was sure it was a little mistake <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=64208&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

Thanks for help!