homepage Welcome to WebmasterWorld Guest from 50.17.162.174
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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




msg:4485156
 6:09 pm on Aug 15, 2012 (gmt 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:

<body>
<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.phpmailer.php");
include("class.smtp.php"); // note, this is optional - gets called from main class if not already loaded
$correophp = new PHPMailer();
$correophp->IsSMTP();
$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\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Nuevo Registro en el sitio de Sepeal</title>
</head>";

$body.="<body>
<h3>Se ha registrado un nuevo usuario en el sitio de Sepeal</h3>
<p>Su nombre y apellidos son: ";
$body.="$nombre ";
$body.="$apellido";
$body.="</p><p>Su correo es: ";
$body.="$mail";
$body.="</p>
</body>
</html>";
$correophp->MsgHTML($body);

$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'];
?>
</div>
</body>
</html>

The last part, where I would expect $correoresult['bien'] to be echoed, is simply ignored.

 

jerry95




msg:4491706
 11:01 pm on Sep 5, 2012 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved