PHP - Phpmailer Not Posting To Email
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. Similar TutorialsI have been taking a crash course trying to learn php/html/javascript/jquery and am probably asking a fairly simple question. I installed phpmailer recently and have been able to send mail with attachments without a problem, but I am trying to make the body of the email HTML. Unfortunately each attempt the formatting is not preserved. I tried copying the same style that I use when I generate the same report to a web page, but it isnt translating to an html email. I have included the code that is relevant. Any glaring oversights? $htmlBody = '<html><head><title>Calls Yesterday</title></head>'; $htmlBody .='<style type="text/css"> body { font-family: Arial, Helvetica, sans-serif; font-size: 16px; } th { font-weight: bold; text-align: left; } td, th { padding: 15px 15px 15px 15px; width: 75px; vertical-align: top; text-align: left; } .outputData2 { margin-left: -10px; margin-right: -10px; width: 500px; } .outputData2 th { white-space: nowrap; text-align: left; padding-right: 10px; } .outputData2 td { white-space: nowrap; text-align: left; } a { text-decoration: none; color: #000; } strong { font-weight: bold; } </style> <br />'; $htmlBody .= '<div style="width: 640px; height: 500px; margin: 10px 0 0 0; padding: 10px; border: 1px solid #e3e3e3; overflow: auto" ><br />'; $htmlBody .= '<table cellpadding="0" cellspacing="0" align="center" class="outputdata2"><br />'; // $htmlBody .= '<table cellpadding="0" cellspacing="0" th="font-weight: bold; width: 25px; padding: 5px,5px,5px,5px; padding-right: 10px; text-align: left; white-space: nowrap;" td="padding: 5px,5px,5px,5px; width: 25px; text-align: left; vertical-align: top; white-space: nowrap;">'; $htmlBody .= '<th>Campaign</th><th>Number of Calls</th><th>Total Call Duration</th><th>Avg Call Duration</th><th>Call Status</th><br />'; // Setup mail class, recipients and body $mailer->AddAddress('me@mail.com', 'PHP Novice'); $mailer->Subject = 'Calls on '.$currentDate.''; $mailer->Body = $htmlBody; $mailer->IsHTML(true); $mailer->AltBody = $textBody; $mailer->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/dashboardOld/campaignFiles/'.$prevClient."_".$currentDate.'.csv', ''.$prevClient."_".$currentDate.'.csv'); $mailer->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/dashboardOld/campaignFiles/'.$prevClient."_".$currentDate.'.json', ''.$prevClient."_".$currentDate.'.json'); $mailer->Send(); $mailer->ClearAddresses(); $mailer->ClearAttachments(); $mailer->IsHTML(false); I even resorted to include the style sheet in what i passed to phpmailer because the formatting wasn't working when i coded the html settings withing $htmlBody originally. Any help would be appreciated. Thanks, Jeff Dear all, I am using PHPMailer to send notification emails after someone submits the form and as a result I'm receiving an email which has only one line: "A new user has been registered to your website". What I want is to receive an HTML email (in a table format) with all the data in it. Data Field Date January 3, 2010 Name: Aaaaa Surname: BBbbb... Email: test@email.com Gender: male .... .... Which code do I need to add in my thanks.php file in order to do this. After filling all the data in www.domain.com/apply.php, it automatically directs the user to thanks.php file Here is my code (thanks.php): <?php require_once("phpMailer/class.phpmailer.php"); require_once("phpMailer/class.smtp.php"); require_once("phpMailer/language/phpmailer.lang-en.php"); $to_name = "My Website"; $to = "email@mydomain.com"; $subject = "A new user has been registered to my website"; $message = "A new user has been registered to my website"; $message = wordwrap($message,70); $from_name = "My Website"; $from = "email@mydomain.com"; //PHP SMTP version $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "mail.website.org"; $mail->Port =25; $mail->SMTPAuth = false; $mail->Username = "username"; $mail->Password = "password"; $mail->FromName = $from_name; $mail->From = $from; $mail->AddAddress($to, $to_name); $mail->Subject = $subject; $mail->Body =<<<EMAILBODY A new user has been registered to my website. EMAILBODY; $result = $mail->Send(); echo $result ? 'Thanks for your registering...' : 'Error'; ?> Hi there, i am trying to send a html using phpMailer and am following this tutorial: http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html I have managed to send an email just fine but when i try to add html to it it doesn't work! I get this message: Mail sent! Fatal error: Call to undefined method FreakMailer::Body() in /hermes/waloraweb018/b1267/moo.organicgrowshopcouk/testemail.php on line 44 This is the code I'm using: <?php // Grab our config settings require_once($_SERVER['DOCUMENT_ROOT'].'/config.php'); // Grab the FreakMailer class require_once($_SERVER['DOCUMENT_ROOT'].'/include/MailClass.inc'); // instantiate the class $mailer = new FreakMailer(); // Set the subject $mailer->Subject = 'This is a test'; // Body $mailer->Body = 'This is a test of my mail system!'; // Add an address to send to. $mailer->AddAddress('info@organicgrowshop.co.uk', 'Matt Johnson'); if(!$mailer->Send()) { echo 'There was a problem sending this mail!'; } else { echo 'Mail sent!'; } $mailer->ClearAddresses(); $mailer->ClearAttachments(); $htmlBody = '<html> <head> <title>My HTML Email</title> </head> <body> <br /> <h2>PHP Freaks Rules!</h2> <p>We invite you to visit <a href="http://www.phpfreaks.com" title="PHP Freaks">PHP Freaks.com</a> for a loving community of PHP Developers who enjoy helping each other learn the language!</p> <p>Sincerely,<br /> PHP Freaks Staff</p>'; $mailer->Body($htmlBody); $mailer->isHTML(true); // Send the E-Mail ?> How do i define method Body() ? Do i need to change something in the phpmailer.class.php file? Sorry if i sound like a complete n00b. I am sending emails using PHPMailer. My configuration is below.
When adding a link to the message, should I use anchor tags? Both seem to work. What is the implication to recipients who are not using HTML email?
On a side note, if anything below seems wrong, please let me know.
Thanks
$msg='<p>Hello</p><p>Link: http://phpmailer.worxware.com/</p><p>Link: http://phpmailer.worxware.com</p><a href="http://phpmailer.worxware.com">http://phpmailer.worxware.com</a>'; $mail = new myPHPMailer(true); $mail->AddReplyTo('myEmail@xxx.com', 'Michael Reed'); $mail->SetFrom('myEmail@xxx.com', 'Michael Reed'); $mail->AddAddress('johndoe@xxx.com', 'John Doe'); $mail->Subject = "Here is your email"; //AltBody property need not be sent since PHPMailer will create an alternate automatically $mail->MsgHTML($message); return ($mail->Send()); class myPHPMailer extends PHPMailer { public function __construct($allow_exceptions=false){ $this->isSMTP(); $this->SMTPDebug = 0; $this->Host = "smtp.gmail.com"; $this->Port = 587; $this->SMTPSecure='tls'; // sets the prefix to the server. Used for gmail only. $this->SMTPAuth = true; $this->Username = 'xxx'; $this->Password = 'xxx'; } } i want to send email to multiple user.this is my code: I have an auctions website and I want to create a feature that is similar to ebay in which users will receive an email if one of the auctions they are watching will end in less than 3 hours. I will be using a cron job to call up this page every 15 minutes. When the cron job executes, I would like it to send 1 email per auction to every user that has that auction on their watchlist if the auction will be ending in 3 hours. I don't know whether it needs to be a separate email for each user or one mass email where their emails are hidden. The 4 tables in my database we are concerned about are "auctions, "users, "watchlists" and "products." I am trying to use the script phpMailer to execute the code because I heard it was the best one. Anways here is what I have so far. I am missing alot because I had no clue what to do. <?php require("class.phpmailer.php"); $holder = mysql_connect("localhost", "user", "password"); mysql_select_db("database", $holder); // NEED TO FIX THIS // Need to get ALL of the auction id's where the end time is less than 3 hours and the notification hasn't already been sent // $auctionid = mysql_query("SELECT id FROM auctions WHERE DATE_ADD(NOW(), INTERVAL 3 HOUR) <= end_time AND notification = 0", $holder); // get the auction title of EACH of the auctions selected above which is not stored in the auctions table but in the products table..will be used for body of email /// AGAIN, NEED THIS TO GET ME ALL OF THE NAMES OF AUCTIONS THAT ARE ENDING IN 3 HOURS// $auctiontitle = mysql_query("SELECT name FROM products LEFT JOIN auctions ON auctions.product_id=products.id WHERE auctions.id = $auctionid", $holder); // PROBABLY NEED TO FIX THIS // Need to get ALL of the email addresses who have ANY of the above auction ids on their watchlist // $email = mysql_query("SELECT email FROM users LEFT JOIN watchlists ON users.id=watchlists.user_id WHERE watchlists.auction_id = $auctionid", $holder); // Update the auctions table. Turn notification to 1 so the notification for that auction can't be sent again // AGAIN NEED THIS FOR ALL OF THE AUCTIONS ENDING IN 3 HOURS // $query1="UPDATE auctions SET notification = '1' WHERE id = '$auctionid'"; mysql_query($query1) or die(mysql_error()); $mail = new PHPMailer(); $mail->From = "no-reply@domain.com"; $mail->FromName = "Site Name"; // Getting and error message for the foreach but I saw a similar example and this is what I was told to do // NEED THIS TO ADD EACH OF THE EMAIL ADDRESSES INDIVIDUALLY // foreach ( $email as $recipients ) { $mail->AddAddress ($recipients); } $mail->WordWrap = 50; // set word wrap to 50 characters $mail->IsHTML(true); // set email format to HTML $mail->Subject = "Your Watched Auction is Ending Soon"; // Sample Body // WANT TO DISPLAY THE TITLE OF THE AUCTION (NAME OF PRODUCT) FOR THE AUCTION ID USING $auctiontile FROM ABOVE // $mail->Body = "Your auction titled $auctiontile is ending soon"; // Same as above // $mail->AltBody = Your auction titled $auctiontile is ending soon"; if(!$mail->Send()) { echo "Message could not be sent."; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "Message has been sent"; ?> I have an email form that is working wonderfully. I have a select box that has a list of names of people that you can email. That list is being pulled from a database. It is currently sending to the email related to the name selected in the dropdown menu. However, in the email that sends, I would like the name of the recipient to show up in the greeting. I.E. Dear "name from dropdown". How do I go about doing this. My select box that holds the query for the name is as folows: <?php echo '<select name="First_and_Last_Name">'; while( $array = mysql_fetch_assoc($result) ) { $text_for_select = $array["First_Name"] . " " . $array["Last_Name"]. " " . $array["District"]; $value_for_select = $array["Email"]; echo "<option></option>\n"; echo "<option value=\"$value_for_select\">$text_for_select</option>\n"; } echo '</select>';?> No, this is querying the First and Last Name and another variable called district in to a new variable called "text_for_select". I just want to either print the "text_for_select" after the "Dear", or better yet, just the "First_Name" and "Last_Name". How would I get this to print there? i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers 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 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. 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 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 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 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 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 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! 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. Hello 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 |