Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Show confirmation message with echo and PHPMailer

Using PHPMailer and gmail sends mail but doesn't echo confirmation message

6:09 pm on Aug 15, 2012 (gmt 0)

New User

5+ Year Member

joined:Jan 31, 2008
posts: 20
votes: 0

Hello, I would appreciate any help with this: I built a registration form and am using PHPMailer to send a confirmation email to the webmaster address, but I can't get the code to echo the confirmation message of the email being sent, the form just empties the fields on submit, as if the page was being reloaded, and the email is sent (this I have checked) but the code that should echo some html in the processing php file doesn't appear. However if I run the code that sends the email in a separate file it does echo the confirmation message, however unfortunately I can't simply do this, I need the code as a part of a larger code that inserts records in a database, etc.
Could anyone advise me on what may be happening?

I post part of the code, where the email is sent:

<div class="wrapper">
<?php if (isset($errorBD)) echo $errorBD; if (isset($errores['nombre']) || isset($errores['apellido'])||isset($errores['mail'])) {echo "Hubo algunos errores en los datos que llenaste: <a href=\"FormatoBasico.php\">Regresar al formato de inscripción?</a><br />"; if (isset($errores['nombre'])) echo $errores['nombre']; if (isset($errores['apellido'])) echo "<br />".$errores['apellido']; if (isset($errores['mail'])) echo "<br />".$errores['mail'];} else if (empty($errores)){mysql_close();
//Código para enviar correo electrónico
include("class.smtp.php"); // note, this is optional - gets called from main class if not already loaded
$correophp = new PHPMailer();
$correophp->SMTPAuth = true; // enable SMTP authentication
$correophp->SMTPSecure = "ssl"; // sets the prefix to the servier
$correophp->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$correophp->Port = 465; // set the SMTP port

$correophp->Username = "gerardo.v.flores@gmail.com"; // GMAIL username
$correophp->Password = "jerry200346602"; // GMAIL password

$correophp->From = "gerardo.v.flores@gmail.com";
$correophp->FromName = "Webmaster Sepeal";
$correophp->Subject = "Nuevo registro en Sitio de Sepeal";
$correophp->AltBody = "This is the body when user views in plain text format"; //Text Body
$correophp->WordWrap = 50; // set word wrap
$body="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Nuevo Registro en el sitio de Sepeal</title>

<h3>Se ha registrado un nuevo usuario en el sitio de Sepeal</h3>
<p>Su nombre y apellidos son: ";
$body.="$nombre ";
$body.="</p><p>Su correo es: ";

$correophp->AddReplyTo("gerardo.v.flores@gmail.com","Webmaster Sepeal");

//$correophp->AddAttachment("/path/to/file.zip"); // attachment
//$correophp->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment

$correophp->AddAddress("gvfb@prodigy.net.mx","Gerardo Flores");

$correophp->IsHTML(true); // send as HTML

if(!$correophp->Send()) {
$correoresult['error']= "Error en el envío del correo: "; echo $correoresult['error'];
} else {
$correoresult['bien']= '<a href="FormatoBasico.php" class="navega">Regresar al formato de inscripción</a><br />'.'<h3>Gracias por registrarte, a continuación te presento un resumen de tu perfil:</h3>'.'<p>El mensaje fue enviado al correo electrónico.</p>';
} if(isset($correoresult['bien'])) echo $correoresult['bien'];

The last part, where I would expect $correoresult['bien'] to be echoed, is simply ignored.
11:01 pm on Sept 5, 2012 (gmt 0)

New User

5+ Year Member

joined:Jan 31, 2008
posts: 20
votes: 0

Nevermind, I found that I was misplacing an else statement and that placing it correctly solved the issue and PHPMailer was able to work with the variables I wanted to echo. It was just a matter of correct syntax and then I was able to correctly get the values of the variables in the script.
I suppose I should close this question.
I apologize for posting the question then realizing it was just a mistake due to a distraction. It was late then.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members