Sending mail using phpMailer

0

I'm trying to send an email with several variables passed via post. I can not send the contents of the email with all the variables. What would be the correct syntax? Here is the code:



$name = $_POST['nome'];
$zip = $_POST['cep'];
$adress = $_POST ['endereco'];
$number = $_POST['numero'];
$comp = $_POST['complemento'];
$neigh = $_POST['bairro'];
$city = $_POST['cidade'];
$state = $_POST['estado'];
$iemail = $_POST['email'];
$phone = $_POST['telefone'];
$product = $_POST['produto'];
$model = $_POST['modelo'];
$brand = $_POST['marca'];
$report = $_POST['laudo'];
$date = $_POST['data'];

require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.meudominio.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';// SMTP username
$mail->Password = 'minhasenha';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, 'ssl' also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('[email protected]', 'Contato');
$mail->addAddress($iemail);     // Add a recipient
$mail->addReplyTo('[email protected]', 'Contato');

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Sua Ordem de Serviço Grupo SAB';
$mail->Body    = '
    <table id="recibo">
        <h1>Ordem de serviço</h1>
        <p>Cliente:'.$name'</p>
        <p>CEP:'.$zip'</p>
        <p>Endereço:'.$adress'</p>
        <p>Numero:'.$number'</p>
        <p>Complemento:'.$comp'</p>
        <p>Bairro:'.$neigh'</p>
        <p>Cidade:'.$city'</p>
        <p>Estado:'.$state'</p>
        <p>Produto:'.$produtc'</p>
        <p>Modelo:'.$model'</p>
        <p>Marca:'.$brand'</p>
        <p>Laudo:'.$report'</p>
    </table>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';

? >

    
asked by anonymous 29.12.2016 / 20:10

1 answer

0

I think your problem is the lack of the . operator to concatenate the variable values with the rest of the string . Note, for example, that in the line of code

<p>Cliente:'.$name'</p>

There is only the concatenation operator before the variable, but not after, which generates a syntax error, since the PHP interpreter will join the '</p> part as part of the string name, generating the error. To fix, simply insert the concatenation operator again after the varable:

<p>Cliente:'.$name.'</p>

Or, if you prefer more organized writing, by making use of sprintf for the string formatting.

Furthermore, it would be a good practice for you to take on future questions to put the error message you are getting into your application already in the scope of the question. It will make life easier for anyone who helps you. You may want to read How NOT to do manual questions .

    
30.12.2016 / 01:37