문제

I have written a basic script for the mail functionality. I am trying to run this script through WAMP server.

<?php
phpinfo();

$to = "mss@xyz.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "mohan.s@xyz.com";
$headers = "From: $from";
$res= mail($to,$subject,$message,$headers);
echo " $res Mail Sent.";
?> 

I have set the SMTP, sendmail_from in the php.ini file . It gives me the following error

Warning: mail() [function.mail]: Failed to connect to mailserver at "mucse409.eu.xyz.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\email.php on line 9 Mail Sent.

I am able to ping the SMTP address from my machine. Please guide me.

도움이 되었습니까?

해결책 3

Following this tutorial I was able to send mail link text.

Send email using Gmail and PHPMailer The new automatic update generator is ready, it has been a long time since OCRALight has been finished and little bit of this and that has been polished on the update generation.

The process is fairly complex, it involves reverse-engineering, data-mining, packaging, distribution and a lot o fighting with our crappy Windows server that is between me and the final Linux liberation.

Every step in the road has been automatized, one by one, every problem has been solved and polished, now the final piece is in his place, the automatic email generation. Now the updates will be made and send everyday, even weekends and vacations.

If you are interested in the technical aspect keep reading:

How it has been done:

First of all, you need to have PHP with OpenSSL support, for Windows you’ll need to Install PHP and carefully select OpenSSL in the components list, if you already have PHP installed, don’t worry a re-install will keep your configuration, and you’ll be able to select OpenSSL.

Then download PHPMailer,&nbsp; and extract it near your main php file.

You will need to have a Gmail account(obviously) I recommend you to make a new one just for this, mainly because the configuration need to be very precise, and you wouldn’t be able to use it freely without loosing functionality or risking to break the configuration.

Configure your Gmail account to use POP mail, but not IMAP, ONLY POP, just POP.

And now the code:

<?php
require(”PHPMailer/class.phpmailer.php”);
$update_emails = array(
    ‘Juan Perez’ => ‘Juan_Perez@jalisco.gob.mx’,
    ‘Francisco Garcia’ => ‘fgarcia@hotmail.com’,
    ‘Diana la del Tunel’ => ‘diana@gmail.com’
  );

echo “\nSending Update Email\n”;

$mail = new PHPMailer();  // Instantiate your new class
$mail->IsSMTP();          // set mailer to use SMTP
$mail->SMTPAuth = true;   // turn on SMTP authentication
$mail->Host = “smtp.gmail.com”; // specify main and backup server
$mail->SMTPSecure= ’ssl’; //  Used instead of TLS when only POP mail is selected
$mail->Port = 465;        //  Used instead of 587 when only POP mail is selected

$mail->Username = “youremail@gmail.com”;  // SMTP username, you could use your google apps address too.
$mail->Password = “yaourextremelynotlamepassword”; // SMTP password

$mail->From = “youremail@gmail.com”; //Aparently must be the same as the UserName
$mail->FromName = “Your name”;
$mail->Subject = ‘The subject’;
$mail->Body = “The body of your message”;

foreach ($update_emails as $name => $email) {
  $mail->AddBcc($email, $name);
}

if(!$mail->Send())
{
  echo “There was an error sending the message:” . $mail->ErrorInfo;
  exit;
}
echo “Done…\n”;
?>

In this code I send the email to a group of people, thus I use the “Bcc:” field instead of the “To:” one, to add a “To:” you would use AddAddress($email, $name).

A possible upgrade would be to use a MySQL database to store the addresses,&nbsp; and provide a web interface to add and remove them. for the moment, this is enough.

Soo remember: PHP with OpenSSL; PHPMailer; Create a Gmail Account; Activate POP Host: smtp.gmail.com; SMTPAuth=true; SMTPSEcure=ssl; Port: 465; User with Domain; Password; $Mail-&gt;send();

다른 팁

Can you also send mail from this machine to this smtp server using some mail client like ms outlook or mozilla thunderbird?

I had a problem once that my provider block traffic directed at smtp ports outside due to virus infection, and I couldn't send mail because of this, but I could ping server and port.

Could be blocked by a firewall or some such.

See if you can open port 25 with telnet (If you don't have software for this, you can download putty)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top