Email PHP SMTP autenticación
Hola,
Alguien sabe un script con smtp autentificacion que funcione bien?
Yo he probado dos, uno no funciona y el otro si funciona, solo que hay un pequeño problema.
Si mando un mail php con un script normal y sencillo (sin la autentificacion) me sale la fecha y hora que se ha enviado el email.
Pero con este script cuando le doy a responder a un email recibido me viene asi:
-----Mensaje original-----
De: Helen@programamail.es [mailto:Helen@programamail.es]
Enviado el: Ninguno
Para: mail@programamail.com; Helen
Asunto: Hello World Again!
Como ve no sale cuando se envió el email, y no sé que hacer, tiene que ser algo en el script que hace que no aparezca cuando se envió.
Este es el script:
<code>
<php>
//new function
$to = "mail@programamail.com";
$nameto = "Helen";
$from = "Helen@programamail.es";
$namefrom = "Test";
$subject = "Hello World Again!";
$message = "World, Hello!";
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>
<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */
//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,
function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "mail.dominio.com";
$port = "587";
$timeout = "30";
$username = "mail@dominio.com";
$password = "contraseña";
$localhost = "localhost";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */
//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}
//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";
//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";
//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";
//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";
//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";
//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";
//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <to>" . $newLine;
$headers .= "From: $namefrom <from>" . $newLine;
fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";
// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
}
<php>
</code>
sgiraldo
rescato este hilo... pq estoy teniendo problemas con el AddEmbedImage del PHPMailer.
estoy intentando enviar una imagen embedida en un cuero de mail, pero la imagen no me la está mostrando.
Tengo este código:
require("class.phpmailer.php");
$nombre = $_GET['n'];
$email = $_GET['e'];
$nombred = $_GET['nd'];
$emaild = $_GET['ed'];
$file = $_GET['f'];
$mail = new PHPMailer();
$mail->From = $email;
$mail->FromName = $nombre;
$mail->Mailer = "smtp";
$mail->Subject = "prueba embed";
$mail->AddEmbeddedImage('http://www.xxxx.com/pub/voto/20081024101008.jpg','myfoto');
$mail->AddAddress($emaild, $nombred);
$mail->IsHTML(true); // enviar como HTML
$body = "Hola <font size='\"4\"'>" . $nombred . "</font>, <p>";
$body .= "Tu amigo <i>".$nombre."</i> te envía la siguiente fotografía.</p><p><img src="cid:myfoto" border="0">";
$mail->Body = $body;
if(!$mail->Send())
{
echo "There has been a mail error sending to " . $row["email"] . "<br>";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
} else{
print "Mensaje enviado";
}
?>
He probado con rutas relativas y de absolutas y no me hace el replace del cid por la imagen.
¿Alguna idea?</p>
helenp
ya lo tengo funcionando,
habia que ponerlo en false como hize, pero tambien habia que elimiar el AltBody, cosa que no hice, pensando que sobrara.
helenp
He encontrado esto tambien en el class.phpmailer.php
<code>
$this->IsHTML(true);
$this->Body = $message;
$textMsg = trim(strip_tags($message));
if ( !empty($textMsg) && empty($this->AltBody) ) {
$this->AltBody = $textMsg;
}
if ( empty($this->AltBody) ) {
$this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
}
}
Y estos comentarios:
/**
* Sets the Body of the message. This can be either an HTML or text body.
* If HTML then run IsHTML(true).
* @var string
*/
var $Body = '';
/**
* Sets the text-only body of the message. This automatically sets the
* email to multipart/alternative. This body can be read by mail
* clients that do not have HTML email capability such as mutt. Clients
* that can read HTML will view the normal Body.
* @var string
*/
var $AltBody
</code>
helenp
dagi3d
para enviar correos en php yo recomiendo PhpMailer: http://phpmailer.codeworxtech.com/
Hola, a ver si puede echar un cable, o alguien que conozca phpmailer.
Lo estoy usando y funciona bien, solo hay una cosa que no me gusta, es que los formularios que rellenan los usuarios, los recibo como email html, y prefiero recibirlos como texto sin formato, porque cuando los conteste se le enviara como html al usuario, y a lo mejor no podrá recibirlo (al menos asi lo tengo entendido, que es mejor mandar textos sin formato).
He visto en dos sitios donde cambiar y no me funciona.
En el php donde viene el formulario hay esto:
$mail->IsHTML(true);
he probado cambiarlo a false y no pasa nada.
En el class.phpmailer hay esto:
<code> function IsHTML($bool) {
if($bool == true) {
$this->ContentType = 'text/html';
} else {
$this->ContentType = 'text/plain';
}
}</code>
He intentado poner text/plain en los dos y tampoco va.
Tiene que poderse configurar para no recibir html digo yo????
helenp
Gracias,
ya lo tengo funcionando y sin problemas, no sé porque andan tantos scripts por la web que no van o tienen fallos.
dagi3d
siempre he dicho que los README son para cobardes y hay que pasar de ellos :P
cuando no tienes acceso al include_path, lo que hay que hacer para poder llamar a los includes es hacerlo poniendo la ruta absoluta del fichero o bien de manera relativa al script que los está llamando.
por ejemplo:
require_once "/home/helenp/www/aplicacion/phpmailer/class.phpmailer.php";
o bien si tu script está en "/home/helenp/www/aplicacion/" y tu clase en "/home/helenp/www/aplicacion/phpmailer/class.phpmailer.php" puedes hacer esto:
require_once "./phpmailer/class.phpmailer.php";
helenp
dagi3d
para enviar correos en php yo recomiendo PhpMailer: http://phpmailer.codeworxtech.com/
Gracias, no sé si lo he entendido bien,
pero en el readme dice esto:
Copy class.phpmailer.php into your php.ini include_path. If you are
using the SMTP mailer then place class.smtp.php in your path as well.
Yo tengo host compartido y no creo que pueda guardar nada en esa carpeta.
Ahora estoy intentando con este y es muy parecido a phpmailer,
pero tampoco me va:
http://www.programacion.net/php/articulo/phpmailer/
dagi3d
para enviar correos en php yo recomiendo PhpMailer: http://phpmailer.codeworxtech.com/