How To Send Mails Using SMTP Server in PHP Cómo enviar mails usando el servidor SMTP en PHP
In PHP on Microsoft Windows you have to simply configure two parameters to enable sending mails through SMTP server. En PHP en Microsoft Windows usted tiene que configurar sólo dos parámetros para permitir el envío de mails a través del servidor SMTP. In Unix / Linux it is slightly more complicated. En Unix / Linux es algo más complicada. The solution, however, is much more powerful and works also on Windows. La solución, sin embargo, es mucho más potente y funciona también en Windows. Let’s first start with Windows. Vamos a empezar con Windows.
In Microsoft Windows PHP installation you just have to change two variables in php.ini: En Microsoft Windows PHP instalación sólo hay que cambiar dos variables en php.ini:
SMTP = smtp.server.com SMTP = smtp.server.com
smtp_port = 25 smtp_port = 25
Replace smtp.server.com with your SMTP server name and 25 with your SMTP server port (normally 25). Sustituir smtp.server.com con su nombre de servidor SMTP y 25 con su servidor SMTP puerto (normalmente 25).
You can also set the default sender information in Windows: También puede establecer el remitente por defecto en Windows información:
sendmail_from = me@example.com sendmail_from = me@example.com
On Linux / Unix PHP relies on sendmail . En Linux / Unix PHP depende de sendmail. You can specify the sendmail path here: Puede especificar la ruta de sendmail aquí:
sendmail_path = /usr/sbin/sendmail -t -i sendmail_path = / usr / sbin / sendmail-t-i
Unfortunately this doesn’t work too well if your SMTP server is configured on a different machine or you are not using sendmail. Lamentablemente esto no funciona demasiado bien si su servidor SMTP está configurado en un equipo diferente, o usted no está usando sendmail.
Fortunately there is a much better solution in Afortunadamente hay una solución mucho mejor en PHPMailer . The default mail capability provided by mail() function in PHP is very limited. La capacidad de correo por defecto proporcionados por mail () en PHP es muy limitado. PHPMailer is a full fledged mail API which can be used to do any kind of mailing tasks. PHPMailer es un pleno derecho mail API que puede ser usado para hacer cualquier tipo de tareas de correo.
Features of PHPMailer Características de PHPMailer
- Can send emails with multiple TOs, CCs, BCCs and REPLY-TOs Puede enviar mensajes de correo electrónico con varios operadores de telecomunicaciones, CC, CB y respuesta-OT
- Redundant SMTP servers Redundantes servidores SMTP
- Multipart/alternative emails for mail clients that do not read HTML email Multiparte / alternativo mensajes de correo electrónico para clientes de correo que no leen el correo electrónico HTML
- Support for 8bit, base64, binary, and quoted-printable encoding Apoyo a 8bit, base64, binario, y citó la codificación de impresora
- Uses the same methods as the very popular AspEmail active server (COM) component Utiliza los mismos métodos como el muy popular AspEmail servidor activo (COM) del componente
- SMTP authentication Autenticación SMTP
- Word wrap Word wrap
- Address reset functions Dirección restablecer las funciones
- HTML email E-mail HTML
- Tested on multiple SMTP servers: Sendmail, qmail, Postfix, Imail, Exchange, etc Probado en varios servidores SMTP: Sendmail, qmail, Postfix, Imail, Exchange, etc
- Works on any platform Obras en cualquier plataforma
- Flexible debugging Flexible de depuración
- Custom mail headers Custom las cabeceras de correo
- Multiple fs, string, and binary attachments (those from database, string, etc) Múltiples fs, cadena, binarios y archivos adjuntos (los de base de datos, cadena, etc)
- Embedded image support Embedded soporte para imágenes
How to use PHPMailer Cómo utilizar PHPMailer
To use PHPMailer you need to first Para utilizar PHPMailer es necesario que usted primero download the files descargar los archivos and save the relevant files (upload) on your server. y guardar los ficheros (upload) en su servidor.
You need to upload class.phpmailer.php , class.smtp.php (for SMTP support) and language/phpmailer.lang-en.php . Debe cargar class.phpmailer.php, class.smtp.php (SMTP para apoyo) y el idioma / phpmailer.lang-en.php. You should download the lang file corresponding to the language of your blog. Usted debe descargar el archivo de idioma correspondiente al idioma de su blog. For my english language sites I use language/phpmailer.lang- en .php , where en is the language code. Para mi idioma Inglés sitios que utilizan language/phpmailer.lang- en. Php, en donde es el código de lenguaje.
In your PHP file include class.phpmailer.php as follows: En su archivo PHP class.phpmailer.php incluir lo siguiente:
if(!class_exists('PHPMailer')) { require(BASEPATH . '/class.phpmailer.php'); } if (! class_exists ( 'PHPMailer')) (exigir (BASEPATH '. / class.phpmailer.php');) Replace BASEPATH with the actual path of class-phpmailer.php file. Sustituir BASEPATH con el camino real de la clase-phpmailer.php archivo. You may also define BASEPATH to achieve the same result (preferred). También puede definir BASEPATH para lograr el mismo resultado (preferido).
Note: This check ensures only one copy of the class is loaded. Nota: Este control que asegura que sólo una copia de la clase es cargado. This in turn loads other required classes. Esto, a su vez otras cargas requeridas clases.
Now you can send a mail using any SMTP server. Ahora puede enviar un correo electrónico utilizando cualquier servidor SMTP. Here is a simple example: Aquí está un ejemplo sencillo:
$mail = new PHPMailer(); $mail->From = $senderemail; $mail->FromName = $sendername; $mail->AddAddress($receiveremail, $receivername); // Fill in Username and Password for servers requiring authentication $mail->Username = $smtp_username; $mail->Password = $smtp_password; // SMTP server name $mail->Host = $smtp_server; $mail->Mailer = "smtp"; $mail->Subject = $mail_subject; $mail->Body = $mail_body; if(!$mail->Send()) $results = 'Error message'; else $results = 'Success message'; $ mail = new PHPMailer (); $ mail-> De senderemail = $, $ mail-> FromName = $ sendername; $ mail-> AddAddress ($ receiveremail, receivername dólares); / / Fill Nombre de Usuario y Contraseña para servidores que requieren autenticación $ mail-> El nombre de usuario = $ smtp_username, $ mail-> Password = $ smtp_password; / / nombre del servidor SMTP $ mail-> Host = $ smtp_server, $ mail-> Mailer = "smtp"; $ mail-> Subject = $ mail_subject $ Mail-> Body = $ mail_body; if ($ mail-> Enviar ()) $ resultados = 'Mensaje de error "; más $ resultados =' Exito mensaje '; You can read the Puede leer la documentation documentación , advanced example avanzada ejemplo or the o la tutorial if you need further help. si necesita más ayuda.
Filed under Filed under Headline News Headline News , How To Cómo , Open Source Software Open Source Software , PHP , Tech Note Nota técnica , Web , Web Services Web Services | |
| |
RSS 2.0 RSS 2,0 | |
Trackback this Article | este artículo |
Email this Article Enviar artículo
You may also like to read También puede leer |




October 9th, 2006 at 1:21 pm 9 de octubre de 2006, a las 1:21 pm
Just a mistake : Sólo un error:
replace : reemplazo de:
require(BASEPATH . ‘/class-phpmailer.php’); requieren (BASEPATH '. / clase-phpmailer.php');
by : por:
require(BASEPATH . ‘/class.phpmailer.php’); requieren (BASEPATH '. / class.phpmailer.php');
October 9th, 2006 at 7:40 pm 9 de octubre de 2006, a las 7:40 pm
Though your comment didn’t come out correctly, I am guessing you were referring to normal single quotes. Aunque su comentario no salió correctamente, me adivinar que estaba refiriéndose a la normalidad comillas simples. This problem is caused by WordPress. Este problema es causado por WordPress. I have corrected this post to He corregido este puesto a remove fancy quotes quitar las comillas de fantasía .
Here’s how you can A continuación le indicamos cómo puede remove fancy quotes quitar las comillas de fantasía from your WordPress blogs or comments. de sus blogs de WordPress o comentarios.
November 7th, 2006 at 2:49 am 7 de Noviembre, 2006 a las 2:49 am
He was actually referring to the fact that the file is named class.phpmailer.php and not class-phpmailer.php as in the original article. Fue en realidad se refiere al hecho de que el nombre del fichero class.phpmailer.php y no de clase-phpmailer.php como en el artículo original.
November 7th, 2006 at 6:41 am 7 de Noviembre, 2006 a las 6:41 am
Ah, thanks. Ah, gracias. Corrected the typo. Corregido el error tipográfico.
January 29th, 2007 at 3:00 am 29 de Enero de 2007 a las 3:00 am
It’s good. Es bueno.
February 4th, 2007 at 11:09 pm 4 de febrero de 2007, a las 11:09 pm
hi… Hola…
im very new to this field…i want something to be done like,if i submit a form ,i should get a mail to im muy nuevo en este campo… i quieren algo que hacer como, si se me presentara un formulario, debo hacerme un correo electrónico a intelevents@kestone.in ….to do tjhis i have followed thw following steps…. …. Tjhis que hacer he seguido thw siguientes pasos….
1..i have uploaded my php file and html file on to server through winSCP… 1 .. he subido mi archivo php y html en el archivo al servidor a través de WinSCP…
2.in browser i opend the file by giving the url kestone.in/reg1.htm.. 2.in navegador i opend el archivo de dar la url kestone.in/reg1.htm ..
but im not getting the mail… pero no im conseguir el correo…
here is my php file aquí está mi archivo PHP
Registration Confirmed Registro Confirmado
Registration Page Inscripción Page
Registration Registro
Salutation: Tratamiento:
‘.$salutation.’ ». $ Saludo '.
FName: Fname:
‘.$fname.’ ». $ Fname '.
Lname : Lname:
‘.$lname.’ ». $ Lname '.
Email-id: Email-ID:
‘. ». $mail.’ $ mail '.
Company: Empresa:
‘. ». $company.’ $ empresa '.
Designation: Designación:
‘. ». $designation.’ $ designación '.
Address1: Dirección1:
‘. ». $Add1.’ $ Add1 '.
Address2: Dirección2:
‘. ». $Add2.’ $ Add2 '.
Address3:
‘. ». $Add3.’ $ Add3 '.
City: Ciudad:
‘. ». $City.’ $ Ciudad '.
State: Estado:
‘. ». $state.’ $ estado '.
Pincode: Código PIN:
‘. ». $pincode.’ $ código pin '.
Phone: Teléfono:
‘. ». $phone.’ $ teléfono. "
Fax:
‘. ». $fax.’ $ fax '.
Mobile: Móvil:
‘. ». $Mobile.’ $ Móvil '.
‘;/* To send HTML mail, you can set the Content-type header. '; / * Para enviar correo HTML, puede configurar el tipo de contenido cabecera. */ * /
$headers = “MIME-Version: 1.0\r\n”; $ cabeceras = "MIME-Version: 1,0 \ r \ n";
$headers .= “Content-type: text/html; charset=iso-8859-1\r\n”; $ cabeceras .= "Content-Type: text / html; charset = iso-8859-1 \ r \ n";
/* additional headers */ / * Cabeceras adicionales * /
$headers .= “From: “.$mail; $ cabeceras .= "De:". $ mail;
/* and now mail it */ / * Y ahora por correo * /
mail($to, $subject, $message, $headers); mail ($ a, $ asunto, $ mensaje, $ cabeceras);
echo ”; echo ";
?> >
and html y HTML
Salutation Saludo
table td.title{ (cuadro td.title
text-align:center;font-family:arial;font-weight:normal;font-size:12px} - alinear texto: centro; font-family: Arial; font-weight: normal; font-size: 12px)
function validation() función de validación ()
{ (
valid = true; válido = true;
objform=document.forms["regform"]; objform = document.forms [ "regform"];
if(objform.Fname.value ==”") if (objform.Fname.value =="")
{ (
alert(”Please enter the ‘First Name’”); alert ( "Por favor, introduzca el 'Nombre'");
objform.Fname.focus(); objform.Fname.focus ();
valid=false; válido = false;
} )
else algo más
if(objform.email.value==”") if (objform.email.value =="")
{ (
alert(”Please enter the Email address”); alert ( "Por favor, introduzca la dirección de correo electrónico");
objform.email.focus(); objform.email.focus ();
valid=false; válido = false;
} )
else algo más
if(objform.company.value==”") if (objform.company.value =="")
{ (
alert(”Please enter the ‘Company’”); alert ( "Por favor, introduzca la" Compañía ");
objform.company.focus(); objform.company.focus ();
valid=false; válido = false;
} )
else algo más
if(objform.designation.value==”") if (objform.designation.value =="")
{ (
alert(”Please enter the designation”); alert ( "Por favor, introduzca la denominación");
objform.designation.focus(); objform.designation.focus ();
valid=false; válido = false;
} )
else algo más
if(objform.add1.value==”") if (objform.add1.value =="")
{ (
alert(”Please fill the ‘Address’”); alert ( "Por favor, rellene el 'Dirección'");
objform.add1.focus(); objform.add1.focus ();
valid=false; válido = false;
} )
else algo más
if(objform.city.value==”") if (objform.city.value =="")
{ (
alert(”Please enter the ‘City’”); alert ( "Por favor, introduzca la 'Ciudad'");
objform.city.focus(); objform.city.focus ();
valid=false; válido = false;
} )
else algo más
if(objform.pin.value==”") if (objform.pin.value =="")
{ (
alert(”Please enter the ‘Pin’”); alert ( "Por favor, introduzca el 'Pin'");
objform.pin.focus(); objform.pin.focus ();
valid=false; válido = false;
} )
else algo más
if(objform.mobile.value==”") if (objform.mobile.value =="")
{ (
alert(”Please enter the ‘mobile number’”); alert ( "Por favor, introduzca el 'número de móvil");
objform.mobile.focus(); objform.mobile.focus ();
valid=false; válido = false;
} )
return valid; retorno válido;
} )
Registration Form Formulario de inscripción
Salutation: Tratamiento:
Dr
Mr Señor
Mrs Sra
Ms Sra
Miss Añorar
*First Name: * Nombre:
Last Name: Apellido:
*Email : * E-mail:
*Company : * Empresa:
*Designation: * Designación:
*Address1: * Dirección1:
Address2: Dirección2:
Address3 : Address3:
*City: * Ciudad:
State: Estado:
*Pin : * Pin:
Phone: Teléfono:
Fax:
*Mobile: * Teléfono móvil:
can anybody help in this issue….its very very very urgent…ill be very thanful to u… nadie puede ayudar en este tema…. su muy muy muy urgente… ser muy malos para thanful u…
February 4th, 2007 at 11:11 pm 4 de febrero de 2007, a las 11:11 pm
Registration Confirmed Registro Confirmado
Registration Page Inscripción Page
Registration Registro
Salutation: Tratamiento:
‘.$salutation.’ ». $ Saludo '.
FName: Fname:
‘.$fname.’ ». $ Fname '.
Lname : Lname:
‘.$lname.’ ». $ Lname '.
Email-id: Email-ID:
‘. ». $mail.’ $ mail '.
Company: Empresa:
‘. ». $company.’ $ empresa '.
Designation: Designación:
‘. ». $designation.’ $ designación '.
Address1: Dirección1:
‘. ». $Add1.’ $ Add1 '.
Address2: Dirección2:
‘. ». $Add2.’ $ Add2 '.
Address3:
‘. ». $Add3.’ $ Add3 '.
City: Ciudad:
‘. ». $City.’ $ Ciudad '.
State: Estado:
‘. ». $state.’ $ estado '.
Pincode: Código PIN:
‘. ». $pincode.’ $ código pin '.
Phone: Teléfono:
‘. ». $phone.’ $ teléfono. "
Fax:
‘. ». $fax.’ $ fax '.
Mobile: Móvil:
‘. ». $Mobile.’ $ Móvil '.
‘;/* To send HTML mail, you can set the Content-type header. '; / * Para enviar correo HTML, puede configurar el tipo de contenido cabecera. */ * /
$headers = “MIME-Version: 1.0\r\n”; $ cabeceras = "MIME-Version: 1,0 \ r \ n";
$headers .= “Content-type: text/html; charset=iso-8859-1\r\n”; $ cabeceras .= "Content-Type: text / html; charset = iso-8859-1 \ r \ n";
/* additional headers */ / * Cabeceras adicionales * /
$headers .= “From: “.$mail; $ cabeceras .= "De:". $ mail;
/* and now mail it */ / * Y ahora por correo * /
mail($to, $subject, $message, $headers); mail ($ a, $ asunto, $ mensaje, $ cabeceras);
echo ”; echo ";
?> >
August 1st, 2007 at 11:29 am Del 1 de agosto de 2007, a las 11:29 am
Realy nice, but is this same for sending email using arabic languages, mean if format is arabic. Realmente agradable, pero es la misma para el envío de correo electrónico utilizando los idiomas árabe, significa si el formato es árabe.