Page 1 of 1

email with PHP on windows server

Posted: Thu Apr 08, 2010 2:53 pm
by aspkiddy
Hi,

How I send an email with PHP on windows server (windows Server Web 2008 and IIS 7.0) with smtp external server.

Into file : php.ini
[mail function]
; For Win32 only.
; SMTP = localhost
SMTP = mail.toto.com
; SMTP = 111.111.1.1
smtp_port = 25
I tried with this code, first time:

Code: Select all


//echo $var_emaill; 
//exit();	
						 
		If (!empty($var_emaill))
		{

$recipient = $var_emaill;
$subject = "confirmation …" ; 
$msg = "hello \t$var_mr \t$var_name\n";
$msg .= "Email : \t$var_emaill\n";
$msg .= "thanks for your inscription\n\n";
$msg .= "Seconde ligne….." ;
$mailheaders = "From: toto.com<> \n"; 

//echo $msg; 
//exit();

// send email
mail($recipient, $subject, $msg, $mailheaders);

}

Here is an error message :
Server Error
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
And after, I tried an other solution :

I installed “phpmailer » : C:\phpmailer\class.smtp.php

And I used an other code, this one :

Code: Select all

<?php 

//echo $var_emaill; 
//exit();

		If (!empty($var_emaill))
		{

//PHP Mailer 
include ("C:\phpmailer\class.smtp.php"); 


// Preparation du mail 

$mail = new PHPmailer();
	$mail->IsSMTP();
	$mail->Host='mail.toto.com';
	$mail->From='toto.com';
	$mail->AddAddress($var_emaill);
	$mail->Subject='confirmation…';
	$mail->Body='hello \t$var_mr \t$var_name\n';
	if(!$mail->Send()){ //Test le return code de la fonction
	  echo $mail->ErrorInfo; //error message
	}
	else{	  
	  echo 'Mail sent with succes';
	}
	$mail->SmtpClose();
	unset($mail);

	
	

} 
?>
I have same error :

Server Error
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

Can you help me : :?: :?: :?:
How must I configure php.ini ?
must I configure class.smtp.php ? If yes how is it ?

my code php (my codes, the two above,) are there correct ?

Best Regards

Re: email with PHP on windows server

Posted: Fri Apr 09, 2010 10:25 am
by Technocrat
Do you really need to use PHP mail()? It would be quicker and less painful to use swiftmailer. http://swiftmailer.org/docs/smtp-transport

Re: email with PHP on windows server

Posted: Fri Apr 09, 2010 1:05 pm
by aspkiddy
Yes I must use PHP because our application use PHP language

Re: email with PHP on windows server

Posted: Fri Apr 09, 2010 1:16 pm
by Technocrat
You misunderstand. Swiftmail is a PHP library that allow you to use email functionality using different transport methods, including SMTP. It also has a number of other useful and powerful features as well.

Re: email with PHP on windows server

Posted: Fri Apr 09, 2010 2:57 pm
by aspkiddy
Hi,

I'm sorry I don,t know that Swiftmail is a PHP...

I tried also an other code, this one :

Code: Select all

<?php
$username = "tototiti";
$password = "tatatete";
$POPserver = "111.111.1.1";
### php.ini's SMTP must correspond to this server
### and sendmail_from must be from this server (??)

$msg = POP_authenticate($username, $password, $POPserver);
if ($msg === FALSE) {
mail("toto@gmail.com", "PHP test", "Line 1\nLine 2");
$msg = "mail (probably) sent.\r\n";
}
exit($msg);
?>
but the same error message :cry:

Re: email with PHP on windows server

Posted: Fri Apr 16, 2010 10:29 am
by aspkiddy
Hi Technocrat,

thanks

It works after I installed phpmailer-1.71 on my web site

this is a my solution for windows web server 2008 :

Copy thoso files class.phpmailer.php and class.smtp.php to your web site



So you have installed phpmailer-1.71


You don't need to change your php.ini file

Then, integrate the following code in your form:

Code: Select all


// Preparation email 

require("class.phpmailer.php"); // ("name_of_your_folder/class.phpmailer.php");)

$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP


$mail->SMTPAuth = true;     // turn on SMTP authentication 
$mail->Host = "111.111.1.1"; // or name of your smtp exemple 111.111.1.1 or smtp.toto.com
$mail->Username = "your_Username";
$mail->Password = "your_Password";
 
$mail->From = "your_email@toto.com";


$mail->AddAddress = "his_email@otot.fr"; //
 
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
 
 
if(!$mail->Send())
{
   echo 'Message was not sent.';
   echo 'Raison : ' . $mail->ErrorInfo;
}
else
{
   echo "Message has been sent.";
}