PHP - Error When Looping With Phpmailer
Hello everyone,
I am trying to do a loop to send emails with phpMailer. I get this error message: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in Someone knows how to fix it??? Greetings, Eddie Similar TutorialsHello all, i currently have a yahoo hosting and since they have a limit of outgoing emails, i want to use smtp to send emails from another server. Below is the code i'm using (phpmailer for PHP 4): <?php include_once("phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPDebug = 1; $mail->SMTPAuth = true; $mail->Host = "mail.domainname.info"; $mail->Port = 25; $mail->Username = "web@domainname.info"; $mail->Password = "password"; $subject = "domainname"; $body = $mail->getFile("message/header-mail.php"); $body = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"540\"> <tr> <td align=\"left\" valign=\"top\" style=\"padding-top: 50px;\" > <span style=\"font-size: 10pt; color: #F58220;\"> text goes here </span> </td> </tr> </tr> </table>"; $body .= $mail->getFile("message/footer-mail.php"); $body = eregi_replace("[\]",'',$body); $mail->From = "noreply@domainname.com"; $mail->FromName = "domainname"; $mail->AddAddress("testemail@gmail.com", "firstname lastname"); $mail->Subject = $subject; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->IsHTML(true); $mail->MsgHTML($body); if ($mail->Send()) { echo "Message sent!"; } else { echo "Mailer Error: " . $mail->ErrorInfo; } ?> the code above gives me this error when i run it: SMTP -> ERROR: Failed to connect to server: No route to host (65) Mailer Error: SMTP Error: Could not connect to SMTP host. The above script is working if i run it directly on the mailing server instead of the yahoo one. Thanks for the help Here is the code I have to process a contact form: <?php // DEFINE VARIABLE AND SET EMPTY VALUES $varfnameErr = $varlnameErr = $varemailErr = $varphoneErr = $varmessageErr = ""; $varfname = $varlname = $varemail = $varphone = $varmessage = $varipaddress = $formerror = $success = ""; $varfnameErr = $_REQUEST['varfnameErr'] ; $varlnameErr = $_REQUEST['varlnameErr'] ; $varemailErr = $_REQUEST['varemailErr'] ; $varphoneErr = $_REQUEST['varphoneErr'] ; $varmessageErr = $_REQUEST['varmessageErr'] ; $varfname = $_REQUEST['varfname'] ; $varlname = $_REQUEST['varlname'] ; $varemail = $_REQUEST['varemail'] ; $varphone = $_REQUEST['varphone'] ; $varmessage = $_REQUEST['varmessage'] ; $varipaddress = $_REQUEST['varipaddress'] ; $message = '<html><body>'; $message .= '<p>Form submitted by: ' .$varfname. ' ' .$varlname. '</p>'; $message .= '<p>Email: ' .$varemail. '</p>'; $message .= '<p>Phone Number: ' .$varphone. '</p>'; $message .= '<p>Message: ' .$varmessage. '</p>'; $message .= '<p>IP Address: ' .$varipaddress. '</p>'; $message .= '</body></html>'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require $_SERVER['DOCUMENT_ROOT'] . '/mail/Exception.php'; require $_SERVER['DOCUMENT_ROOT'] . '/mail/PHPMailer.php'; require $_SERVER['DOCUMENT_ROOT'] . '/mail/SMTP.php'; $mail = new PHPMailer; $mail->isSMTP(); $mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages $mail->Host = "HostIsBlueHost"; // use $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6 $mail->Port = 21; // TLS only $mail->SMTPSecure = 'tls'; // ssl is deprecated $mail->SMTPAuth = true; $mail->Username = 'info@aacroofing.org'; // email $mail->Password = 'PasswordWasHere'; // password $mail->setFrom($varemail); // From email and name $mail->addAddress('test@gmail.com'); // to email and name $mail->Subject = 'Contact Us Form Submission'; $mail->msgHTML($message); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded, $mail->AltBody = 'HTML messaging not supported'; // If html emails is not supported by the receiver, show this body //$mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); if(!$mail->send()){ echo "Mailer Error: " . $mail->ErrorInfo; }else{ $success = "<p class='success'>Message sent! Thank you!</br>IP Address: " .$varipaddress. " recorded</p>"; $varfname = $varlname = $varemail = $varphone = $varmessage = ""; } ?>
When the form is completed and submitted this is the error that I get. I have no idea what this means. If someone understands the error, could you please give me a clue?
2020-03-08 19:48:46 SERVER -> CLIENT: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------220-You are user number 1 of 150 allowed.220-Local time is now 13:48. Server port: 21.220-IPv6 connections are also welcome on this server.220 You will be disconnected after 15 minutes of inactivity. I have the most simple loop ever on this earth an its doin strange things. There are 6 rows in my cache table. I have a query to echo the rows onto the page with a loop. Now Im try to limit the rows returned to 1 row. simples eh. $FetchCacheq = mysql_query("SELECT * FROM cacheInfo LIMIT 1") or die('cache error'); <table width="480" border="0" cellpadding="0" cellspacing="5"> <tr> <td colspan="2" valign="baseline"><strong>Caches you have found</strong></td> </tr> <?php do { ?> <tr> <td width="250" height="31" align="left" valign="middle"><?php echo $row['cacheName'];?></td> <td width="230" align="left" valign="middle"><img src="/images/submit.png" width="20" height="20" /></td> </tr> <?php } while($row = mysql_fetch_assoc($FetchCacheq));?> </table> The problem I have is its showing two rows. Here is the source code from the page <table width="480" border="0" cellpadding="0" cellspacing="5"> <tr> <td colspan="2" valign="baseline"><strong>Caches you have found</strong></td> </tr> <tr> <td width="250" height="31" align="left" valign="middle"></td> <td width="230" align="left" valign="middle"><img src="/images/submit.png" width="20" height="20" /></td> </tr> <tr> <td width="250" height="31" align="left" valign="middle">Your Life in Their Hands</td> <td width="230" align="left" valign="middle"><img src="/images/submit.png" width="20" height="20" /></td> </tr> </table> as you can see one of the rows doesnt even have the cache name in it!!! please help im really confused. Hi all,
I have a looping error in my PHP.
I am trying to add use a while statement to gather the users first and last name in to a string, add them to an array called $friendname, then check that the $friendname[] is only output/echoed once.
At the moment the code looks good to me but with multiple rows with the same name associated, the name is echoed the same amount of times as rows, instead of once as it is supposed to be.
Any ideas anyone?
while($row2 = mysqli_fetch_assoc($result2)) { $friendcode = $row2['Code']; $names = "SELECT FirstName, LastName from users WHERE Code = '$friendcode' AND Code != '$crewcode'"; $resultnames = mysqli_query($cxn,$names) or die ("Can't get friends names."); while($rownames = mysqli_fetch_assoc($resultnames)) { $friendname = array(); $newfriendname = ($rownames['FirstName'].' '.$rownames['LastName']); if (!in_array($newfriendname, $friendname)) { array_push($friendname, "$newfriendname"); echo $newfriendname; } } } hey guys im using phpmailer (https://github.com/PHPMailer/PHPMailer) to send mail from my server to users using SMTP...the problem im getting is that when i send a mail it goes stright into the junk mail...how can i please stop this please?
$mail = new \Mail\Mail; $mail->isSMTP(); $mail->Debugoutput = 'html'; $mail->Host = "****"; $mail->Port = 25; $mail->SMTPAuth = true; $mail->Username = "****"; $mail->Password = "***"; $mail->setFrom('***', '****'); $mail->addAddress('email@hotmail.co.uk', 'user'); $mail->Subject = 'BiSi - Welcome'; $mail->msgHTML('<a href="test">hello</a>'); $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; if (!$mail->send()) { echo "Mailer Error: "; } else { echo "Message sent!"; } Will someone, who doesn't mind helping an old man understand some things, explain how to use PHPMailer?
You see, I downloaded a registration form that sends a verification e-mail. I'm testing all of this on my local machine (Linux). The mail, of course, fails to be delivered. So I surf around and see where phpmailer can help me with this. So I downloaded phpmailer-master. But I have absoultely no idea where to put what so I'll have e-mail capability from localhost.
If you can tell me what goes where, I promise to name my next child after ya I just need some guidance on this one. It has me totally confused!
Landslyde
PS: Happy 2015 to all!
Edited by Landslyde, 30 December 2014 - 11:17 PM. Hi. I'm using PHP mailer. But I can't get it to send the Email: Class: Code: [Select] public function send_notification($sendTo, $name, $from_name, $from_email, $body_content, $subject){ $message =<<<EMAILBODY {$body_content} EMAILBODY; $message = wordwrap($message, 70); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "localhost"; $mail->Port = 25; $mail->SMTPAuth = false; $mail->isHTML(TRUE); $mail->FromName = $from_name; $mail->From = $from_email; $mail->AddAddress($sendTo, $name); $mail->Subject = $subject; $mail->Body = $message; $result = $mail->Send(); return $result; } PHP Code: [Select] $body_content = ' Dear BusinessMobile.com <br /><br /> A website user has filled in the form on the website. See the details below. <br /><br /> Company: '.$company.'<br /> Name: '.$name.'<br /> Email: '.$email.'<br /> Tele: '.$telephone.'<br /> Message: '.$message.'<br /><br /> Interest: '.$Fpage.'<br /> Reference: '.$ref.'<br /><br />'; $subject = 'BusinessMobile.com - Contact Request'; Form_signup::send_notification('spires1@mail.com', 'BM', 'BM', 'spires1@mail.com', $body_content, $subject); Any ideas where i'm going wrong ? Thanks Hello, I am a PHP beginner and I made a PHP page which inserts data into a MYSql database. .... $InsertQuery->Action = "insert"; $InsertQuery->Table = "klanten"; $InsertQuery->bindColumn("Klantnummer", "s", "".strtoupper(((isset($_POST["Klantnummer"]))?$_POST["Klantnummer"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Naam_organisatie", "s", "".strtoupper(((isset($_POST["Naam_organisatie"]))?$_POST["Naam_organisatie"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Adres_organisatie", "s", "".strtoupper(((isset($_POST["Adres_organisatie"]))?$_POST["Adres_organisatie"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Postcode_organisatie", "s", "".strtoupper(((isset($_POST["Postcode_organisatie"]))?$_POST["Postcode_organisatie"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Woonplaats_organisatie", "s", "".strtoupper(((isset($_POST["Woonplaats_organisatie"]))?$_POST["Woonplaats_organisatie"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("BTW_plichtig", "s", "".strtoupper(((isset($_POST["BTW_plichtig"]))?$_POST["BTW_plichtig"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Email", "s", "".strtoupper(((isset($_POST["Email"]))?$_POST["Email"]:"")) ."", "WA_DEFAULT"); ... After the insert, I want to send all the data with a mail to a recepient. But I can't find a way to code the "setForm" correctly with the inserted field "Email". <?php error_reporting(E_ALL); use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\src\Exception; require 'PHPMailer\PHPMailer\src\Exception.php'; require 'PHPMailer\PHPMailer\src\PHPMailer.php'; require 'PHPMailer\PHPMailer\src\SMTP.php'; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp.myhosting.be"; $mail->SMTPAuth = true; $mail->Username = 'username@domain.com'; $mail->Password = 'password'; $mail->setFrom = $_POST('Email'); // doesn't work $mail->AddAddress('recipient@domain.com'); $mail->Subject = "subject"; $mail->Body = "text"; // in the body I want an overview of all the inserted data $mail->IsHTML(true); if(!$mail->Send()) { echo "Error sending: " . $mail->ErrorInfo;; } $mail->ClearAddresses(); $mail->ClearAttachments(); ?>
How can I do that? I am trying to get phpmailer working but not having much luck with it. I am not receiving the email Below is the code I have <?php //index.php $error = ''; $quantity1 = ''; $totalprice1 = ''; $subtotal = ''; $postage = ''; $grandtotal = ''; $name = ''; $addressline1 = ''; $postcode = ''; $email = ''; function clean_text($string) { $string = trim($string); $string = stripslashes($string); $string = htmlspecialchars($string); return $string; } if(isset($_POST["submit"])) { if(empty($_POST["quantity1"])) { $error .= '<p><label class="text-danger">Please enter the quantity required</label></p>'; } if(empty($_POST["totalprice1"])) { $error .= '<p><label class="text-danger">Please enter the total price required</label></p>'; } if(empty($_POST["subtotal"])) { $error .= '<p><label class="text-danger">Please enter the subtotal</label></p>'; } if(empty($_POST["postage"])) { $error .= '<p><label class="text-danger">Please enter the postage</label></p>'; } if(empty($_POST["grandtotal"])) { $error .= '<p><label class="text-danger">Please enter the grand total</label></p>'; } if(empty($_POST["name"])) { $error .= '<p><label class="text-danger">Please Enter your name</label></p>'; } else { $name = clean_text($_POST["name"]); if(!preg_match("/^[a-zA-Z ]*$/",$name)) { $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>'; } } if(empty($_POST["addressline1"])) { $error .= '<p><label class="text-danger">Please enter your address line 1</label></p>'; } if(empty($_POST["postcode"])) { $error .= '<p><label class="text-danger">Please enter your postcode</label></p>'; } if(empty($_POST["email"])) { $error .= '<p><label class="text-danger">Please Enter your Email</label></p>'; } else { $email = clean_text($_POST["email"]); if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error .= '<p><label class="text-danger">Invalid email format</label></p>'; } } if($error == '') { require 'phpmailer/class.phpmailer.php'; $mail = new PHPMailer(true); $mail->SMTPDebug = 1; // to see exactly what's the issue $mail->IsSMTP(); //Sets Mailer to send message using SMTP $mail->Host = 'hostname'; //Sets the SMTP hosts $mail->Port = '587'; //Sets the default SMTP server port $mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables $mail->Username = 'emailaddress'; //Sets SMTP username $mail->Password = 'emailaddresspassword'; //Sets SMTP password $mail->SMTPSecure = ''; //Sets connection prefix. Options are "", "ssl" or "tls" $mail->From = $_POST["email"]; //Sets the From email address for the message $mail->FromName = $_POST["name"]; //Sets the From name of the message $mail->AddAddress('emailaddress', 'Name');//Adds a "To" address $mail->AddCC($_POST["email"], $_POST["name"]); //Adds a "Cc" address $mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters $mail->IsHTML(true); //Sets message type to HTML $mail->Subject = "Online Badge Order"; //Sets the Subject of the message $mail->Body = "The order information is below" . "<br><br>" . "Club One: " . $_POST["club1"] . "<br>" . "Country One: " . $_POST["country1"] . "<br>" . "Ref No: " . $_POST["refno1"] . "<br>" . "Quantity: " . "<br>" . $_POST["quantity1"] . "<br>" . "Total Price Line: " . "\243" . $_POST["totalprice1"] . "<br><br>" . "Club Two: " . $_POST["club2"] . "<br>" . "Country Two: " . $_POST["country2"] . "<br>" . "Ref No: " . $_POST["refno2"] . "<br>" . "Quantity: " . $_POST["quantity2"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice2"] . "<br><br>" . "Club Three: " . $_POST["club3"] . "<br>" . "Country Three: " . $_POST["country3"] . "<br>" . "Ref No: " . $_POST["refno3"] . "<br>" . "Quantity: " . $_POST["quantity3"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice3"] . "<br><br>" . "Club Four: " . $_POST["club4"] . "<br>" . "Country Four: " . $_POST["country4"] . "<br>" . "Ref No: " . $_POST["refno4"] . "<br>" . "Quantity: " . $_POST["quantity4"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice4"] . "<br><br>" . "Club Five: " . $_POST["club5"] . "<br>" . "Country Five: " . $_POST["country5"] . "<br>" . "Ref No: " . $_POST["refno5"] . "<br>" . "Quantity: " . $_POST["quantity5"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice5"] . "<br><br>" . "Club Six: " . $_POST["club6"] . "<br>" . "Country Six: " . $_POST["country6"] . "<br>" . "Ref No: " . $_POST["refno6"] . "<br>" . "Quantity: " . $_POST["quantity6"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice6"] . "<br><br>" . "Club Seven: " . $_POST["club7"] . "<br>" . "Country Seven: " . $_POST["country7"] . "<br>" . "Ref No: " . $_POST["refno7"] . "<br>" . "Quantity: " . $_POST["quantity7"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice7"] . "<br><br>" . "Club Eight: " . $_POST["club8"] . "<br>" . "Country Eight: " . $_POST["country8"] . "<br>" . "Ref No: " . $_POST["refno8"] . "<br>" . "Quantity: " . $_POST["quantity8"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice8"] . "<br><br>" . "Club Nine: " . $_POST["club9"] . "<br>" . "Country Nine: " . $_POST["country9"] . "<br>" . "Ref No: " . $_POST["refno9"] . "<br>" . "Quantity: " . $_POST["quantity9"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice9"] . "<br><br>" . "Club Ten: " . $_POST["club10"] . "<br>" . "Country Ten: " . $_POST["country10"] . "<br>" . "Ref No: " . $_POST["refno10"] . "<br>" . "Quantity: " . $_POST["quantity10"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice10"]; //An HTML or plain text message body if($mail->Send()) //Send an Email. Return true on success or false on error { header('Location:thank-you.html'); } else { $error = '<label class="text-danger">There is an Error</label>'; } $quantity1 = ''; $totalprice1 = ''; $subtotal = ''; $postage = ''; $grandtotal = ''; $name = ''; $addressline1 = ''; $postcode = ''; $email = ''; } } ?>
I am new to phpmailer and still trying to learn and understand it, I can do the basics in it if want to just use it to send a email but now want to use it to send attachments but the attachments are optional and only want to be able to send jpg and png attachments but am trying to concentrate on one thing at a time but getting frustrated with it. I am currently trying to get it so that the attachments are not required so if the user sends the form with no attachments, the form sends all ok and the same as if the user sends attachments, below is my current code but is not working, am getting unexpected errors as either ; or } $attachmentNames = []; //Attach multiple files one by one for ($ct = 0; $ct < count($_FILES['userfile']['tmp_name']); $ct++) { $uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])); $filename = $_FILES['userfile']['name'][$ct]; if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) { $mail->addAttachment($uploadfile, $filename); $attachmentNames[] = $_FILES['userfile']['name'][$ct]; } else { $msg .= 'Failed to move file to ' . $uploadfile; } if ($mail->addAttachment { $msg .= 'Failed to attach file' } } $mail->Subject = 'New Repair Booking Made At' . ' ' .date('d-m-Y H:i:s'); $mail->Body = "A new repair has been booked in. This repair booking was made at " . $date = date('d-m-Y H:i:s') . "\r\n\r\n" . "The repair information is below" . "\r\n\r\n" . "Repair Date/Time: " . $_POST["date"] . "\r\n" . "Device: " . $_POST["selectdevice"] . "\r\n" . "Brand: " . $_POST["selectbrand"] . "\r\n" . "Name: " . $_POST["name"] . "\r\n" . "Email: " . $_POST["email"] . "\r\n" . "Phone Number: " . $_POST["phone"] . "\r\n" . "Repair Description/Issue: " . $_POST["repairdescription"] . "\r\n\r\n" . "Attached Filename(s): " . implode(', ', $attachmentNames);
I am working on a webform that sends an email when submitted. The following output appears intermittently on the form.php page (I have currently disabled the page forwarding so I can see the output more easily). I am not quite sure what is going on, but when this occurs, no email is sent. Here's what the output looks like: Code: [Select] SMTP -> FROM SERVER: SMTP -> FROM SERVER: SMTP -> ERROR: HELO not accepted from server: SMTP -> FROM SERVER: SMTP -> ERROR: MAIL not accepted from server: Message could not be sent. Mailer Error: SMTP Error: From address [myemail@myserver.com] failed This same file and same configuration has worked on and off, even when no changes are made. It seems that maybe the server is simply denying connections for some reason, but I'm not entirely sure, hence the post here. Any suggestions or ideas for debugging are GREATLY appreciated. Thanks! I am setting up PHPMailer to send pdf's from my server and I have just come into the following error: Quote Deprecated: Function set_magic_quotes_runtime() is deprecated in /var/www/PHPMailer_v5.1/class.phpmailer.php on line 1471 Deprecated: Function set_magic_quotes_runtime() is deprecated in /var/www/PHPMailer_v5.1/class.phpmailer.php on line 1475 The code in question is this (I've pointed out the lines mentioned above): Code: (php) [Select] <?php /** * Encodes attachment in requested format. * Returns an empty string on failure. * @param string $path The full path to the file * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' * @see EncodeFile() * @access private * @return string */ private function EncodeFile($path, $encoding = 'base64') { try { if (!is_readable($path)) { throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); } if (function_exists('get_magic_quotes')) { function get_magic_quotes() { return false; } } if (PHP_VERSION < 6) { $magic_quotes = get_magic_quotes_runtime(); set_magic_quotes_runtime(0); //<-- Here } $file_buffer = file_get_contents($path); $file_buffer = $this->EncodeString($file_buffer, $encoding); if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); } //<-- Here return $file_buffer; } catch (Exception $e) { $this->SetError($e->getMessage()); return ''; } } So my question is, how can I get rid of this error? How should I best edit this function to no longer use the deprecated set_magic_quotes_runtime()? Any help is appreciated, Joe I downloaded the PHPMailer. I can send email from gmail mail server to the registered users in my website smoothly. But when I upload it to my web host basically I edited all the credentials and apply my new host mail server username, password, host, port, etc. When i try to send this is the error: Code: [Select] SMTP Error: Authentication Failed and this is my code Code: [Select] <?php session_start(); ?> <html> <head> <title>PHPMailer - SMTP (Gmail) basic test</title> </head> <body> <form action="GET"> <?php $pEmail = $_SESSION['uEmail']; $pUser = $_SESSION['user']; $eTitle = $_SESSION['uTitle']; $eDesc = $_SESSION['uDesc']; $ePrice = $_SESSION['uPrice']; //error_reporting(E_ALL); error_reporting(E_STRICT); //date_default_timezone_set('America/Toronto'); require_once('class.phpmailer.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); //$body = file_get_contents('contents.php'); //$body = eregi_replace("[\]",'',$body); $body = "Welcome to GankGames, ".$pUser. "<br><br> Your Game has been uploaded successfully!<br><br> Below is the summary of your upload transaction: <br><br> Game Name: ".$eTitle."<br> Game Description: ".$eDesc."<br> Game Price: ".$ePrice."<br><br> Your game will be verified in 24 hours for security purposes. After verifying we will going to send you again an email informing you that your game is already active <br><br><br> Thank you very much!!"; $mail->IsSMTP(); // telling the class to use SMTP $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // sets the prefix to the servier $mail->Host = "mail.********.com"; // sets GMAIL as the SMTP server $mail->Port = 465; // set the SMTP port for the GMAIL server $mail->Username = "gankgames@almarioit115p.com"; // GMAIL username $mail->Password = "*********"; // GMAIL password $mail->SetFrom('mail.********.com', 'admin@gankgames.com'); //$mail->AddReplyTo("teitoklein01@gmail.com","jm"); $mail->Subject = "Game Verification"; //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $address = $pEmail; $mail->AddAddress($address, $pUser); //$mail->AddAttachment("images/phpmailer.gif"); // attachment //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { //echo "Message sent!"; //$_SESSION['uploaded'] = "Uploaded Successfully"; $upload = "Uploaded Successfully"; ob_start(); header("Location: confirm.php?pupload=$upload"); ob_end_flush(); } ?> </form> </body> </html> help I have been away from a coding project for over 2 years. Trying to get things online, and not cause further delays. My site uses the PHP Mailer class to send out emails to users for things like password resets. How important is it that I have the latest version of this class - assuming it is even still around now? Thanks.
I am still fairly new to using phpmailer and it works but I have been asked to google recaptcha v2 checkbox into their contact form but unsure how to do that within the phpmailer code, below is what I currently have <?php // PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Base files require 'PHPMailer/src/Exception.php'; require 'PHPMailer/src/PHPMailer.php'; require 'PHPMailer/src/SMTP.php'; // create object of PHPMailer class with boolean parameter which sets/unsets exception. $mail = new PHPMailer(true); try { //$mail->isSMTP(); // using SMTP protocol $mail->Host = 'hostname'; // SMTP host as gmail $mail->SMTPAuth = true; // enable smtp authentication $mail->Username = 'emailaddress'; // sender gmail host $mail->Password = 'emailpassword'; // sender gmail host password $mail->SMTPSecure = 'ssl'; // for encrypted connection $mail->Port = 587; // port for SMTP $mail->setFrom('emailaddress', "Business Name"); // sender's email and name $mail->addAddress('emailaddress', "Business Name"); // receiver's email and name $mail->Subject = 'New Website Enquiry'; $mail->Body = "A new website enquiry has been made. The enquiry information is below" . "\r\n\r\n" . "Name: " . $_POST["name"] . "\r\n" . "Email: " . $_POST["email"] . "\r\n" . "Subject: " . $_POST["subjectline"] . "\r\n" . "Message: " . $_POST["message"]; $mail->send(); header('Location:enquiry-confirmation.php'); } catch (Exception $e) { // handle error. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; } ?>
Hello,
I am sending an email via phpmailer to a large group of recipients.
I bcc'd the entire group which of course failed after the max limit was reached so I thought what about sending in chunks....
Im just trying to figure out how to loop through the groups of bcc's
basically Im thinking something like this...
$mail = new PHPMailer(true); $mail->IsSMTP(); //setup from, replyto etc here... //email query here to get emails in array $bccz.. //chunk results $newArray = array_chunk($bccz, 50, false); // Now process array_chunk() $i = 0; foreach ($newArray as $inner_array) { $i++; while (list($key, $value) = each($inner_array)) { addBCC($value['email']); }$subject = '=?UTF-8?B?'.base64_encode($cobig).'?='; $mail->Subject = $subject; $mail->IsHTML(true); $mail->Body = $ermail; $mail->Send(); } $mail->clearBcc(); }Just wondering if someone can tell me if this basic logic is right?
How do I only allow jpg and png file extensions to be uploaded as a attachment. My current code is below $msg = ''; if (array_key_exists('userfile', $_FILES)) { // create object of PHPMailer class with boolean parameter which sets/unsets exception. $mail = new PHPMailer(true); try { //$mail->isSMTP(); // using SMTP protocol $mail->Host = 'host'; // SMTP host as gmail $mail->SMTPAuth = true; // enable smtp authentication $mail->Username = 'emailaddress'; // sender gmail host $mail->Password = 'emailpassword'; // sender gmail host password $mail->SMTPSecure = 'ssl'; // for encrypted connection $mail->Port = 587; // port for SMTP $mail->setFrom('emailaddress', "Name"); // sender's email and name $mail->addAddress('emailaddress', "Name"); // receiver's email and name $attachmentNames = []; //Attach multiple files one by one for ($ct = 0; $ct < count($_FILES['userfile']['tmp_name']); $ct++) { $uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])); $filename = $_FILES['userfile']['name'][$ct]; if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) { if(isset($uploadfile)) $mail->addAttachment($uploadfile, $filename); $attachmentNames[] = $_FILES['userfile']['name'][$ct]; } else { $msg .= 'Failed to move file to ' . $uploadfile; } }
So I am trying to use PHP mailer on my site however it doesn't post to the email Here is the code: Top: <?php
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/phpmailer/phpmailer/src/Exception.php'; Where it sends: require 'vendor/autoload.php';
//Instantiation and passing `true` enables exceptions
I have tried everything but it still won't post. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=359340.0 |