Taking src value of an image to send e-mail in phpmailer

Asked

Viewed 736 times

0

On my page, I’m trying to get an email sent with data from a form to be filled in. One of the fields is an image, which can be changed depending on the selected option:

<tr>
<td style="text-align: left">Layout: </td>
<td>
    <select name='layout' style="font-family: Trebuchet MS; font-size: 20px; width: 400px" onchange="document.getElementById('imgCamp').src = this.options[this.selectedIndex].value;">
        <option value="images/campanhas/img0001.jpg">Imagem 1</option>
        <option value="images/campanhas/img0002.jpg">Imagem 2</option>
        <option value="images/campanhas/img0003.jpg">Imagem 3</option>
    </select>
</td>
</tr>
<tr>
<td colspan="2"><!-- Abaixo é a imagem preview da campanha -->
    <img id="imgCamp" style="width: 560px; margin-top: 20px; margin-bottom: 20px" src="images/campanhas/img0001.jpg">
</td>
</tr>

But I would like the selected image to appear in the email. Follow the e-mail sending code below:

    if(isset($_POST['btnEnvia'])){ // TODO Falta uma função pra poder enviar o e-mail   
    $unidade        = $_POST['unidade'];
    $solicitante    = $_POST['solicitante'];
    $tipoMaterial   = $_POST['tipoMaterial'];
    $layout         = $_POST['layout'];
    $imgCamp        = 'http://201.7.201.173/MktMaterial/' . 'images/campanhas/img0001.jpg';
    $texto1         = $_POST['texto1'];
    $texto2         = $_POST['texto2'];

    require 'phpmailer/class.phpmailer.php';

    $mail = new PHPMailer();
    $mail->IsSMTP(); // send via SMTP
    $mail->Host = 'mail.intercityhoteis.com.br'; // SMTP servers
    $mail->Port = 25; // SMTP servers
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = '[email protected]'; // SMTP username
    $mail->Password = 'intercity@123'; // SMTP password
    $mail->From = '[email protected]';
    $mail->FromName = 'Teste';
    $mail->AddAddress('[email protected]');
    $mail->IsHTML(true); // send as HTML

    $mail->Subject = 'Solicitação de Material de Marketing - Unidade ' . $unidade;

    // corpo da mensagem
    $mail->Body = '<html>
        <body>
            <div>
                <div style="text-align: center; font-family: Trebuchet MS; font-size: 16px;"><img src="http://201.7.201.173/MktMaterial/images/intercity.png"></img><br><br>Solicitação de material de Marketing:</div>
                <br><br>Unidade: '.$unidade.'
                <br>Solicitante: '.$solicitante.'
                <br>Tipo de Material: '.$tipoMaterial.'
                <br><br>Layout: '.$layout.'
                <br><br><img style="width: 560px; margin-top: 20px; margin-bottom: 20px" src='.$imgCamp.'>
                <br><br>Texto: '.$texto1.'
                <br><br>Observações: '.$texto2.'
            </div>
        </body>
    </html>';

    // corpo da mensagem em modo texto
    $mail->AltBody = 'Mensagem em texto';

    // verifica se enviou corretamente
    if ( $mail->Send() ) {
        echo "<script>
            alert('Pedido enviado!');
        </script>";
    }
    else {
        echo 'Erro do PHPMailer: ' . $Mailer->ErrorInfo;
    }
}

I thought the $imgCamp variable might get something like:

$imgCamp = 'http://201.7.201.173/MktMaterial' . ?>$('#imgCamp').val();<?php

Actually what I want is for it to receive the value of the chosen src of imgCamp in my html. How can I do this?

  • 1

    The value of imgCamp will always be the same as chosen in the field select ?

  • That’s right. How can I put in the code?

1 answer

0


So according to your html code, just take the value of the select layout, because its value is the same as src, due to javascript changing src according to the value of select.

  • OK, it worked!!! I put it to him to receive the value $_POST['layout']. Thanks for the answers, friends.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.