![]()
non riesco ad inviare una semplice mail attraverso un form con il seguente codice:
<form method="post" action="send.php">
Nome <input type="text" name="nome" id="nome" />
Cognome <input type="text" name="cognome" id="cognome" />
E-mail <input type="text" name="email" id="email" />
Oggetto <input type="text" name="oggetto" id="oggetto" />
Testo del messaggio
<textarea name="messaggio" id="messaggio" rows="7" cols="40"></textarea>
<input type="submit" value="Invia" /> <input type="reset" value="cancella" />
</form>
ed il send.php:
<?php
print("inizio script
");
ini_set("username","paolo.gasparroni.pse");
ini_set("password","xxxxxxxxx");
$value = $_POST['email'];
$messaggio = $_POST['messaggio'];
if(preg_match( '/^[w.-]+@w+[w.-]*?.w{1,4}$/', $value))
die("Indirizzo email non valido");
else {
if(empty($messaggio))
{
echo "Messaggio non inviato con successo
";
}
else
{
mail("paolo.gasparroni.pse@gmail.com", $_POST['oggetto'], $_POST['messaggio'], "From: ".$_POST['email']);
echo "Messaggio inviato con successo
";
print($_POST['messaggio']."
");
}
}
print("fine script");
?>
visualizzo la seguente pagina di risposta alla form inviata:
inizio script
Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. w1sm1144183weq.1 in C:\www\send.php on line 17
Messaggio inviato con successo
cippa
fine script
Ho impostato in php.ini le seguenti variabili:
[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 465
; For Win32 only.
sendmail_from = paolo.gasparroni.pse@gmail.com
protrebbe essere un problema di autenticazione?
Per ovviare a questo mi sono scaricato l'ultima versione di PHPMailer_v5.1
utilizzando come send quello di esempio di PHPMailer:
invio la richiesta sempre attraverso la form e chiamo il seguente send.php preso dagli esempio
specifico per gmail che vuole l'autenticazione:
dei parametri della form non mi interesso visto che è un esempio di funzionamento:
<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "paolo.gasparroni.pse@gmail.com"; // GMAIL username
$mail->Password = "xxxxxxxx"; // GMAIL password
$mail->SetFrom('paolo.gasparroni.pse@gmail.com', 'First Last');
// $mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "paolo.gasparroni.pse@gmail.com";
$mail->AddAddress($address, "Paolo Gasparroni");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
ricevendo in risposta il seguente errore:
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (24)
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
aiutatemi non riesco a venirne a capo ... grazie in anticipo!!!