Problem with submitting php

0

I'm getting some blank emails, it just comes from an email "MISSING_MAILBOX @ syntax_error". The others come all right, with the client email that fills out the form

define( 'OWNER_EMAIL', '[email protected]' );

define( 'DONOTREPLY_EMAIL', '[email protected]' );

define( 'OWNER_NAME', 'Menegalli' );

case 'quote-form':   

        # put the email title here
        $title = 'Nova simulação via website';

        # email headers
        $headers = "MIME-Version: 1.0\n".
                   "Content-type: text/html; charset=utf-8\n".
                   "Content-Transfer-Encoding: 8bit\n".
                   "From: ". $_POST['clientName'] ." <". $_POST['clientEmail'] .">\n".
                   "Reply-to: ". $_POST['clientName'] ." <". $_POST['clientEmail'] .">\n".
                   "Date: ". date( "r" ). "\n";

        # appointment values
        $values = $_POST['values'];

        # create rows with values from appointment form
        $rows = '';
        for( $i = 0; $i < count( $values ); $i++ ) {

            $rows .= '<tr>

                          <td style="width: 200px; font-weight: bold; border: 1px solid #eee; padding: 10px;">'. $values[$i]['name'] .'</td>
                          <td style="border: 1px solid #eee; padding: 10px;">'. $values[$i]['value'] .'</td>

                      </tr>';
        }

        # email content
        $content = '<table style="width: 600px; font-size: 11px; border-collapse: collapse;">'. $rows .'</table>';

        # sending an email
        $result = mail(
            OWNER_EMAIL,
            "=?UTF-8?B?". base64_encode( $title ) ."?=",
            $content,
            $headers
        );

        # if the email wasn't send
        if( $result == false ) {

            # second version of email
            mail(
                OWNER_EMAIL,
                "=?UTF-8?B?". base64_encode( EMAIL_TITLE ) ."?=",
                $content
            );
        }

    break;

Has anyone ever been through this?

Follows an image of the email source that comes with no content and email that comes with content From the left is what comes without the content and the right comes with the content. The problem seems to be that some emails are not picking up the fields: '. $ values [$ i] ['name']. ' and '. $ values [$ i] ['value']. '

    
asked by anonymous 31.08.2016 / 19:32

1 answer

0

The problem occurs because of a lack of verification in the client's email content.

When you use the expression:

"From: ". $_POST['clientName'] ." \n".

Note that in the image, on the left side, FROM and REPLY-TO are empty . You are informing that the email will be sent by the content contained in the variables $_POST['clientName'] and $_POST['clientEmail'] . Ideally, in this situation, you validate the contents of the same, or send from an email of yours ([email protected]), which is more recommended (yahoo emails, for example, would have difficulty reaching the destination).

I would use it like this:

if (empty($_POST['clientEmail']) {
    throw new RuntimeException('Email não preenchido', 1);
}
# email headers
$headers = "MIME-Version: 1.0\n".
  "Content-type: text/html; charset=utf-8\n".
  "Content-Transfer-Encoding: 8bit\n".
  "From: Simulação do Site <[email protected]>\n".
  "Reply-to: ". $_POST['clientName'] ." <". $_POST['clientEmail'] .">\n".
  "Date: ". date( "r" ). "\n";
This way, you will not lose emails in the validations of the email servers (yahoo, google, etc ...) and still guarantee that the client has filled the clientEmail variable.

References

link link

    
02.09.2016 / 20:40