1

I am trying to sent a email to a already existing email address using STMP Server on a Wamp Server host locally. Here with smtp.gmail.com on port 465, the page freeze and loads indefinitely. All the variables are good, I didn't put every of them here.

I try smtp.live.com but I got "Client was not authenticated to send anonymous mail" while I gave the correct logins. I don't know the name of the internet provider (homework context) I cannot use the SendEmail solution or any other plug-ins in the context of my homework. I hide the password for oblivious reasons in the code, but it won't work even with the correct one.

if (!preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#", $mail)) // On filtre les serveurs qui rencontrent des bogues.
            {
                $passage_ligne = "\r\n";
            }
            else
            {
                $passage_ligne = "\n";
            }

            //=====Création de la boundary
            $boundary = "-----=".md5(rand());
            //==========
            //=====Création du header de l'e-mail.
            $header = "From: \"ECE Amazon\"<ece20192@gmail.com>".$passage_ligne;
            $header.= "Reply-to: \"ECE Amazon\" <ece20192@gmail.com>".$passage_ligne;
            $header.= "MIME-Version: 1.0".$passage_ligne;
            $header.= "Content-Type: multipart/alternative;".$passage_ligne." boundary=\"$boundary\"".$passage_ligne;
            //==========

            //=====Création du message.
            $message = $passage_ligne."--".$boundary.$passage_ligne;
            //=====Ajout du message au format texte.
            $message.= "Content-Type: text/plain; charset=\"ISO-8859-1\"".$passage_ligne;
            $message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
            $message.= $passage_ligne.$message_txt.$passage_ligne;
            //==========
            $message.= $passage_ligne."--".$boundary.$passage_ligne;
            //=====Ajout du message au format HTML
            $message.= "Content-Type: text/html; charset=\"ISO-8859-1\"".$passage_ligne;
            $message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
            $message.= $passage_ligne.$message_html.$passage_ligne;
            //==========
            $message.= $passage_ligne."--".$boundary."--".$passage_ligne;
            $message.= $passage_ligne."--".$boundary."--".$passage_ligne;
            //==========

            //=====Envoi de l'e-mail.
            ini_set("SMTP", "smtp.gmail.com");
            ini_set("smtp_port","465");
            ini_set("default_domain", "smtp.gmail.com");
            ini_set("force_sender", "ece20192@gmail.com");
            ini_set("sendmail_from", "ece20192@gmail.com");
            //ini_set("auth_username", "ece20192@gmail.com");
            //ini_set("auth_password", "");
            mail($mail,$sujet,$message,$header);
            //==========

The client is to supposed to received a email on his email adress with a short message. The SMTP server is supposed to accepted by request for sending an email.

Tom
  • 11
  • 1
  • Possible Duplicate of [PHP mail function doesn't complete sending of e-mail](//stackoverflow.com/q/24644436). Gmail authorization is [not gonna work](https://stackoverflow.com/questions/112190/php-ini-smtp-how-do-you-pass-username-password) with the built-in mail() function. You will *have to* setup a local smtp relay, or use one of the more reliable and simpler email classes. – mario May 03 '19 at 17:18
  • There is no mail server on Windows by default. Did you install one – RiggsFolly May 03 '19 at 17:19
  • You can set up XAMPP to send emails from SMTP, so that calls to the mail() function from your PHP will send via SMTP. Not sure it if works with WAMP but I guess you can give it a try: https://stackoverflow.com/questions/15965376/how-to-configure-xampp-to-send-mail-from-localhost – Anis R. May 03 '19 at 17:50
  • I would strongly suggest debugging this with [PHPMailer](https://github.com/PHPMailer/PHPMailer) first, then come back to `mail()` – Machavity May 03 '19 at 17:56
  • Thanks for the clarifications! I wasn't suppose to install anything but i will give a shot to the sendmail.exe that seems to work for others – Tom May 03 '19 at 17:57

0 Answers0