简体   繁体   中英

why the mail doesnt send automatically?

The idea is send mails automatically to my users when left a day to expire the suscription.

$enviar = $datoMesPazysalvo[2] - $ayer;
    if($enviar == 1){

        $nombre = $row_registroClientes['nombres'] + $row_registroClientes['apellidos'];
        $email = $row_registroClientes['correo'];
        $telefono = $row_registroClientes['telefono'];

        // multiple recipients
        $to  = 'info@vulpini.co' . ', '; // note the comma
        $to .= '$email';

        // subject
        $subject = 'Fight Club Bogota, Información importante!!';

        // message
        $message = '
        <html>
        <head>
          <title>Fight Club Bogota, Información importante!!</title>
        </head>
        <body>
          <p>Tu matricula vence mañana $datoMesPazysalvo[2]</p>
          <span>Ponte en contacto con nosotros para renovar</span>
        </body>
        </html>
        ';

        // To send HTML mail, the Content-type header must be set
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        // Additional headers
        $headers .= 'To: $nombres <$email>, Administrador <info@vulpini.co>' . "\r\n";
        $headers .= 'From: Administrador <administrador@fightclubbogota.com>' . "\r\n";

        // Mail it
        mail($to, $subject, $message, $headers);

    }

why is the reason this doesnt work?, i think the logic is right but i don't completely sure, if rightly.

i hope someone can help me.

Thanks so much.

It's quite difficult to tell without knowing what "$ayer" and "$datoMesPazysalvo[2]" types and values are.

For this whole piece:

$enviar = $datoMesPazysalvo[2] - $ayer;
if($enviar == 1)

I'd recommend you to encapsulate that logic into a function "shouldSendEmail" which you can unit test and make sure that you get the right output every time:

if(shouldSendEmail(){
...
}

What exactly doesnt work?

If it's not sending mail... first, if you send out a php testmail, check that it works, using the mail() function in its most simplistic form (leave out the additional headers):

mail("youremail@address.es","test subject line","test body");

(just replace the email address to yours).

If it doesnt work, your e-mail facility/service (sendmail?) may not be set up correctly or may be misconfigured.

If it works then probably you're not constructing your variables correctly. Instead of the mail() statement, insert this and run your code again to see if the variables are ok as they should be...

var_dump($to);
var_dump($subject);
var_dump($message);
var_dump($headers);

Hope this helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM