Jump to content

email with PHP on windows server


aspkiddy

Recommended Posts

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:

 

 

//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 :

 

 
<?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

Link to comment
https://forums.phpfreaks.com/topic/198039-email-with-php-on-windows-server/
Share on other sites

I tried this one also :

 

<?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("[email protected]", "PHP test", "Line 1\nLine 2");
$msg = "mail (probably) sent.\r\n";
}
exit($msg);
?>

 

 

 

but the same error message

 

:confused::rtfm: :-\

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:

 


// 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 = "[email protected]";


$mail->AddAddress = "[email protected]"; //

$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.";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.