bootstrap mail form $from<$email> $fromEmail

131 Views Asked by At

I refer to this page. https://bootstrapious.com/p/how-to-build-a-working-bootstrap-contact-form and i uesd index-2.html / contact-2.php files.

i want mailheader ''

but code is

**$fromEmail = '[email protected]';
$fromName = 'Demo contact form';**
$sendToEmail = '[email protected]';
$fields = array('name' => 'Name', 'phone' => 'Phone', 'email' => 'Email', "\r\n" , 'message' => 'Message');

so i changed

$fromEmail = "$email" $fromName = '$name'; or
$fromEmail = $_POST['form_email'];  $name = $_POST['name'];

but It just makes an error. ex) Root User" '

try
{

if(count($_POST) == 0) throw new \Exception('Form is empty');

$emailTextHtml .= "<table>";

foreach ($_POST as $key => $value) {
    // If the field exists in the $fields array, include it in the email
    if (isset($fields[$key])) {
        $emailTextHtml .= "<tr><th>$fields[$key]</th><td>$value</td></tr>";
    }
}
$emailTextHtml .= "</table>";

$mail = new PHPMailer;

$mail->setFrom($fromEmail, $fromName);
$mail->addAddress($sendToEmail, $sendToName); // you can add more addresses by simply adding another line with $mail->addAddress();
$mail->addReplyTo($from);

$mail->isHTML(true);

$mail->Subject = $subject;
$mail->msgHTML($emailTextHtml); // 

what should I do?

$fromEmail = '[email protected]'; $fromName = 'Demo contact form'

How should I change it?

0

There are 0 best solutions below