B_CooperA Posted October 2, 2013 Share Posted October 2, 2013 He'res my function for sending a reminding email every time user has pressed the "Remind" -button. I'm testing it out with two different mail providers, Gmail and Outlook and it does work with Outlook but don't send any emails to my Gmail.. It did work when I was using the old mail() - function, but when I moved to PHPMailer, it stopped working. Here's my code: public function remindUser() { $query = "SELECT * FROM users INNER JOIN user_events ON user_events.userID = users.user_id INNER JOIN events ON events.event_id = user_events.eventID WHERE events.event_id = :event_id"; $stmt = $this->connect->prepare($query); $stmt->execute(array( ':event_id' => $_POST['event_id'] )); $rows = $stmt->rowCount(); if($rows == 0) { // Jos ei onnistu, siirretään käyttäjä Googleen (?) $this->error[] = "Tapahtumaan ei ole osallistunut kukaan"; } else { while($this->row = $stmt->fetch(PDO::FETCH_ASSOC)) { // Osoitteet $addresses[] = $this->row['email']; $to = implode(", ", $addresses); // Sähköpostiviestin aihe $subject = "Tapahtuman ".$this->row['event_name']. " muistutusviesti sivustolta SportieTown"; // HTML - pohja sähkäpostille $template = "<html><body> <div class='header' style='background-color: #f67004; width: 700px; height: 60px;'> <img src=\"cid:logoimg\" style='float: right; margin-right: 20px;' /> <h1 style='color: #ffffff; float: left; margin-left: 20px;''>Hei, ".$this->row['name']."!</h1></div>\n\n <p style='color: #333333; font-size: 13px; font-family: Verdana; float:left;'> Tämä on automaattinen viesti, joka lähetettiin SportieTown-käyttäjän <b>".$_SESSION['name']."n</b> toimesta\n\n <p style='color: #333333; font-size: 11px; font-family: Verdana; float:left;'> SportieTownin käyttäjä ".$_SESSION['name']. " halusi muistuttaa sinua tapahtumasta <b>".$this->row['event_name']."</b>, joka järjestetään".date("d.m.Y", strtotime($this->row['event_date']))." kello " .$this->row['event_time']. "\n <p style='color: #333333; font-size: 11px; font-family: Verdana; float:left;'><i>Muistathan siis osallistua tapahtumaan\n\n Terveisin, SportieTownin väki</i></p> </body></html>"; require("phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsMail(); $mail->IsHTML(true); $mail->AddAddress($to); $mail->AddEmbeddedImage('logo-small.png', 'logoimg', 'logo-small.png'); $mail->Subject = $subject; $mail->Body = $template; if(!$mail->Send()) { header("location:http://www.google.fi"); } else { header("location:profile.php?id=".$_SESSION['user_id'].""); } Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted October 2, 2013 Share Posted October 2, 2013 you need to at least provide us with the domain where your sending mail server is at. also, you are not setting a from address (i'm betting when you used the mail() function, you were setting a from address.) Quote Link to comment Share on other sites More sharing options...
B_CooperA Posted October 2, 2013 Author Share Posted October 2, 2013 (edited) Yeah, the actual problem is not with the Gmail.. It's just sending the email to one user.. I pasted my code again in here, since I can't edit my original post. So what I'm doing wrong? public function remindUser() { $query = "SELECT * FROM users INNER JOIN user_events ON user_events.userID = users.user_id INNER JOIN events ON events.event_id = user_events.eventID WHERE events.event_id = :event_id"; $stmt = $this->connect->prepare($query); $stmt->execute(array( ':event_id' => $_POST['event_id'] )); $rows = $stmt->rowCount(); if($rows == 0) { // Jos ei onnistu, siirretään käyttäjä Googleen (?) $this->error[] = "Tapahtumaan ei ole osallistunut kukaan"; } else { while($this->row = $stmt->fetch(PDO::FETCH_ASSOC)) { require("phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); // Osoitteet $addresses[] = $this->row['email']; $to = implode(",", $addresses); // Sähköpostiviestin aihe $subject = "Tapahtuman ".$this->row['event_name']. " muistutusviesti sivustolta SportieTown"; // HTML - pohja sähkäpostille $template = "<html><body> <div class='header' style='background-color: #f67004; width: 700px; height: 60px;'> <img src=\"cid:logoimg\" style='float: right; margin-right: 20px;' /> <h1 style='color: #ffffff; float: left; margin-left: 20px;''>Hei, ".$this->row['name']."!</h1></div>\n\n <p style='color: #333333; font-size: 13px; font-family: Verdana; float:left;'> Tämä on automaattinen viesti, joka lähetettiin SportieTown-käyttäjän <b>".$_SESSION['name']."n</b> toimesta\n\n <p style='color: #333333; font-size: 14px; font-family: Verdana; float:left;'> SportieTownin käyttäjä ".$_SESSION['name']. " halusi muistuttaa sinua tapahtumasta <b>".$this->row['event_name']."</b>,joka järjestetään".date("d.m.Y", strtotime($this->row['event_date']))." kello " .$this->row['event_time']. "\n <p style='color: #333333; font-size: 11px; font-family: Verdana; float:left;'><i>Muistathan siis osallistua tapahtumaan\n\n Terveisin, SportieTownin väki</i></p> </body></html>"; $mail->IsMail(); $mail->IsHTML(true); $mail->AddEmbeddedImage('images/logo-small.png', 'logoimg', 'images/logo-small.png'); $mail->AddAddress($to); $mail->Subject = $subject; $mail->Body = $template; if(!$mail->Send()) { header("location:http://www.google.fi"); } else { header("location:profile.php?id=".$_SESSION['user_id'].""); } header("location: profile.php?id=".$_SESSION['user_id'].""); } return count($this->error) ? 0 : 1; } } Edited October 2, 2013 by B_CooperA Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted October 3, 2013 Share Posted October 3, 2013 I don't use phpMailer, but it sounds like you never sent anybody a message with a gmail account.Have you ever tried some debugging steps to debug the output of this $to variable?Something like: $to = implode(", ", $addresses); echo '<pre>'.print_r($to, true).'</pre>'; Also, what happens if you try to set two or more outgoing messages to different mail servers in the AddAddress() method? $mail->AddAddress("userName@outlook.com","userName@gmail.com"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.