English 中文(简体)
sendmail() php help
原标题:

I am getting an error while sending a mail from a form

Failed to connect to mailserver at "mail.yoursite.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:xamppxampphtdocssend.php on line 8

Warning: mail() [function.mail]: SMTP server response: 550 ACCESS DENIED in C:xamppxampphtdocssend.php on line 9

Message delivery failed...

here is the code

mail.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="send.php" action="POST">
Enter Name : <input type="text" name="name" />
Enter E-Mail : <input type="text" name="email" />

Enter Subject: <input type="text" name="subject" />

Enter Message: <input type="text" name="mess" />

<input type="submit" name="Submit" />
</form>
<?php

?>



</body>
</html>

send.php

<?php
$name = $_POST[ name ];
$email = $_POST[ email ];
$body = $_POST[ subject ];
$message=$_POST[ message ];
//ini_set("sendmail_from","name@yoursite.com");
//ini_set("SMTP","mail.yoursite.com");
mail("name@yoursite.com", $name, $message, "From :$from");
if (mail( nishantmshah@gmail.com , $name, $body, $message, "From :$from")) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>
最佳回答

You re using a win32 version of php and its smtp-implementation of mail(). It s a tiny little MTA that can t do authentication of any kind. If the smtp server you re trying to relay the email to requires you to authenticate mail() will fail.
Either use (and configure) sendmail for win32. Or a mailer class/library that implements authentication, e.g. SwiftMailer.

btw: Xampp bundles the mercury smtp server. In its default configuration it accepts emails from local php scripts. But then you have to configure mecury to relay the emails to another MTA .

问题回答

The message SMTP server response: 550 ACCESS DENIED suggests to me that you should check your credentials for that server again. Your username, or password may be incorrect.

You need to install this PEAR Module if you wish to use authentication as it is not provided in the mail function of PHP.

Sending Mail from PHP Using SMTP Authentication - Example

<?php
require_once "Mail.php";

$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,

How are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ( From  => $from,
   To  => $to,
   Subject  => $subject);
$smtp = Mail::factory( smtp ,
  array ( host  => $host,
     auth  => true,
     username  => $username,
     password  => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>

basicaly if you are on a hosted server then sending an email with php is easy as drinking cold water.

if(mail( to@bla.bla , subject , content here i include sometime var_export($var,1) ))
 echo  email send succefull ;
else
  echo  emaiol coudnt be send ;

if you send this from your localmachine this will mostly fail because most server refuse requests like this. Then you have to use an external library for sending your email from a service like gmail.

As VolkerK pointed - use Swiftmail, its selfcontained, no need for a SMTP server. I used two days with Mercury + xampp, couldnt make it work.

First example in this link works right away:

http://swiftmailer.org/docs/sending.html





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签