Problem with php Submit

Asked

Viewed 69 times

0

I’m getting some blank emails, it just comes from an email "MISSING_MAILBOX@syntax_error". The others come all straight, with the email of the customer who fills 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;

Someone’s been through it?

Follows an image of the email source code that comes with no content and email that comes with content.inserir a descrição da imagem aqui 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 : '. $values[$i]['name'] fields. ' and '. $values[$i]['value'] .'

1 answer

0

The problem occurs due to lack of verification in the content of the client’s email.

When you use the expression:

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

See that in the image, on the left, the FROM and the REPLY-TO are empty. You are stating 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 content of them, or send from an email from you ([email protected]), which is more recommended (yahoo emails, for example, would have difficulty reaching the destination).

I would use it as follows:

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 ensure that the client has completed the clientEmail variable.

References

http://php.net/manual/en/function.empty.php http://php.net/manual/en/language.exceptions.php

  • There are emails that arrive with the content, but there are some that are not enough.

Browser other questions tagged

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