¡Ups! Ahora veo el problema. Está utilizando las variables de su formulario, por ejemplo, $FirstName
antes de haber sido asignados.
Mueve tu $mail->Body
Asignación debajo de su // Form fields
bloquear.
:)
Pregunta
Tengo una configuración de formulario PHP con SMTP SendGrid. El formulario se envía bien, pero los correos electrónicos salen sin ninguno de los datos incluidos. El formulario HTML tiene nombre coincidente = ... ¿Qué estoy haciendo mal?
Primer nombre:
Apellido:
Compañía:
Título profesional:
Correo electrónico:
Teléfono:
Mensaje:
require("phpmailer.php");
$mail = new PHPMailer();
// SMTP & Sendgrid settings
$mail->IsSMTP();
$mail->Host = "smtp.sendgrid.net";
$mail->Port = "NNN";
$mail->SMTPAuth = "true"; // Enable SMTP authentication
$mail->Username = "username";
$mail->Password = "password";
$mail->SMTPSecure = ''; // Enable encryption, 'ssl' also accepted
// Email headers and body
$mail->SetFrom("myemail@email.com");
$mail->AddAddress("myemail@email.com");
$mail->Subject = "Message from site.com";
$mail->Body = "You have a new message from your contact form on site.com \n \n First Name: $FirstName \n Last Name: $LastName \n Company: $Company \n Job Title: $JobTitle \n Email: $Email \n Phone: $Phone \n Message: $Message";
$mail->WordWrap = 50;
// Form fields
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Company = $_POST['Company'];
$JobTitle = $_POST['JobTitle'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Message = $_POST['Message'];
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else {
echo 'Message has been sent.';
}
Aquí está el HTML:
<form id="ContactForm" class="form" method="POST" action="http://staging.shipmenthq.com/mail.php" onsubmit="validateForm()">
<div class="formRow">
<div class="formHalf padRight">
<label>*First Name:</label>
<input type="text" name="FirstName">
</div>
<div class="formHalf">
<label>*Last Name:</label>
<input type="text" name="LastName">
</div>
</div>
<div class="formRow">
<span class="formFull">
<label>*Company:</label>
<input type="text" name="Company">
</span>
</div>
<div class="formRow">
<span class="formFull">
<label>*Job Title:</label>
<input type="text" name="JobTitle">
</span>
</div>
<div class="formRow">
<span class="formFull">
<label>*Email:</label>
<input type="email" name="Email">
</span>
</div>
<div class="formRow">
<span class="formFull">
<label>*Phone Number:</label>
<input type="tel" name="Phone">
</span>
</div>
<div class="formRow">
<span class="formFull">
<label>Message:</label>
<textarea name="Message"></textarea>
</span>
</div>
<div class="formRow">
<span class="formFull">
<input type="submit" value="Submit Form" class="button" />
</span>
</div>
</form>
Solución
¡Ups! Ahora veo el problema. Está utilizando las variables de su formulario, por ejemplo, $FirstName
antes de haber sido asignados.
Mueve tu $mail->Body
Asignación debajo de su // Form fields
bloquear.
:)