PHP - Get Unread Gmail Messages In Php
I am trying to run this but it wont work. I get the following error. Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox in /home/u984345410/public_html/default.php
Here is a snipit of the code Code: [Select] function CountUnreadMails($login, $passwd) { $mbox = imap_open("{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox", $login, $passwd, OP_READONLY); $count = 0; if (!$mbox) { echo "Error"; } else { $headers = imap_headers($mbox); foreach ($headers as $mail) { $flags = substr($mail, 0, 4); $isunr = (strpos($flags, "U") !== false); if ($isunr) $count++; } } imap_close($mbox); return $count; } Similar TutorialsI cant get this to work and I found a host with imap-ssl here is my code though i've been messing around with it. It cant get the imap_open to work. Code: [Select] $mbox = imap_open ("{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox", "username", "password", OP_READONLY) or die("can't connect: " . imap_last_error()); $check = imap_mailboxmsginfo($mbox); echo $check->Unread; / Please please help. Thanks Hello. My first topic here was about getting the amount of unread messages. I'm now working on showing the unread messages in the inbox. Let's say we have 2 users. User1 sends user2 a message with the title: this is a title. User2 read the message and replied. User1 now has to see: this is a title. This is the code in: class Pm {} public function get_unread_pm() { $stmt = $this->db->prepare(' SELECT pm.title, pm.sender_id, pm.timestamp, (SELECT COUNT(pm2.id) FROM pm as pm1, pm as pm2 WHERE pm1.parent_id=pm2.id) AS replies, u.username as sender FROM pm LEFT JOIN users AS u ON u.id=pm.sender_id WHERE pm.receiver_id=:user_id AND pm.unread=1 AND pm.parent_id=pm.id'); $stmt->bindParam('user_id', $_SESSION['userid']); $stmt->execute(); return $stmt->fetchAll(); } I now get the original message because of the pm.parent=pm.id, but I want to get the message where the parent_id of a reply is the same parent_id as where the parent_id is equal to it's id. I think a less complicated description is: How do I get the last reply instead of the original message?
parent_id: When I reply to a message, my id still counts up, the parent_id is the id of the original message. This is what my data-table looks like:
The content:
If I'm doing this stuff really inefficient, I would be happy to know how to make it better Fabian Edited September 19, 2019 by FabelHey, im trying to create a little function that displays how many unread messages a user has this is my function Code: [Select] function unread() { $sql_pm_r = mysql_query("SELECT COUNT(*) FROM messages WHERE reciever=" . $user . " AND recieved='0'"); $num_rows = mysql_num_rows($sql_pm_r); $sql_pm_check = mysql_query("SELECT id FROM messages WHERE reciever=" . $user . " AND recieved='0' LIMIT 1"); $num_new_pm = mysql_num_rows($sql_pm_check); if ($num_new_pm > 0) { $pms = '<a href="inbox.php" >('.$num_rows.')</a>'; } else { $pms = '<a href="inbox.php" >(0)</a>'; } echo $pms; }and i'm calling it on the index page as normal like Code: [Select] unread(); However not matter how many unread messages i have, i always get (0), this is how my sql table looks id reciever sender subject message recieved Hi, I am learning pdo php and mysql
I would like to know how to see whether a record has been read or not. I have a database messages with id, user_id, contact_id, login, msg, rrecord and msgtime.
The rrecord column has been set as 0 as default. When the client clicks the msg link, I would like it to update the rrecord to 1.
Thanks.
How is it possible, in PHP, to display an error message next to a form input text field if a user is attempting to submit a form with empty fields? Moreover, how is it possible to remove the same error message when the user fills in the input field with the required data and/or refreshes the page? I have 2 files that I am working with: application.php and process.php.
application.php mainly has the HTML of the form. I am very new to learning PHP (I started learning it last week) and I have been searching for hours for a clear answer. I have already tried different methods for generating the error message including: using empty(), !isset, $_POST["name"] = "", etc, and have tried using session_start();, $row, echo, print, and other variables to try and display error message on the page, and I have tried using unset();, and = null, to try and remove the error message once the input field has been filled but all to no avail. Either the method I try only half works, or nothing works, and I cannot pinpoint which is the part that is not working. I only have 2 files to work with, and as an example of what I want to do is:
1. If the first name field is empty when the user clicks submit, an error message should appear next to the input. Is this possible with PHP? Hello World ! i got this script of PM system on my website where 2 or 3 users can send PM to each other it work ok but it <?php header : PM (unread count) $msgs_count = GetUnreadMessagesCount($session_user["id"]); and got this in the Index header : PM <span>( <?=$msgs_count;?> )</span> /* Hello World ! i got a website where 2 or 3 users can create and send PM everything work good but have this bug . */ Example message thread#id1 Sender: A send the message to B & C ok now B & C got PM (1) B make reply to this PM and C the same now the bug is userA will have PM(2) like he have 2unread messages but is different reply in the same message so need to count only (1) by Thread not reply ok if A read it and send new reply now B & C will have PM (3) i hope someone can help me with this code thank you ! this is message_tbl for database <?php $tbl_messages_fields = array( "id" => "INTEGER PRIMARY KEY AUTO_INCREMENT", "threadId" => "INT(11)", "type" => "VARCHAR(4)", "heldById" => "INT", "fromId" => "INT", "toId" => "VARCHAR(32)", "isRead" => "INT(1) $d0", "isStarred" => "INT(1) $d0", "isDeleted" => "INT(1) $d0", "subject" => "VARCHAR(150)", "message" => "VARCHAR(10000)", "timestamp" => "INT(12)"); SetupTable('tbl_messages', $tbl_messages_fields); function UpdateMessageField($conditions, $field, $value){ global $dbPrep; $add = array(); foreach($conditions as $key=>$val){ $add[] = "`$key`=:$key"; } $add = implode(" AND ", $add); $sql = "UPDATE `tbl_messages` SET $field=:$field WHERE $add"; $query = $dbPrep->prepare($sql); $data = array_merge($conditions, array("$field"=>$value)); $query->execute($data); } function GetMessagesQuery($data = array(), $complexConditions = "", $extra = ""){ $dbPrep = GetDatabaseConnection(); $sql = "SELECT * FROM `tbl_messages` "; $add = " "; foreach($data as $key=>$value){ $add.= "AND `$key`=:$key "; } $add = ($add != " ") ? "WHERE" . substr($add, 4, strlen($add)) : $add; $sql.= $add." ".$complexConditions." ".$extra; $query = $dbPrep->prepare($sql); $query->execute($data); return GetRows($query); } function GetThreadQuery($conditions = array(), $complexConditions = "", $extra = ""){ global $dbPrep; $add = array(); foreach($conditions as $key=>$val){ $add[] = "`$key`=:$key"; } $add = implode(" AND ", $add); $sql = "SELECT a.*, b.username AS fromUsername, b.type AS fromType FROM `tbl_messages` AS a "; $sql .= "INNER JOIN `tbl_users` AS b ON a.fromId=b.id "; $sql .= "WHERE $add ORDER BY timestamp ASC"; #echo $sql; $query = $dbPrep->prepare($sql); $query->execute($conditions); return GetRows($query); } $p_NewMessage = $dbPrep->prepare("INSERT INTO `tbl_messages` (type, threadId, heldById, fromId, toId, subject, message, timestamp) VALUES (:type, :threadId, :heldById, :fromId, :toId, :subject, :message, :timestamp);"); $sql = "SELECT a.*, b.type as fromType FROM `tbl_messages` AS a "; $sql .= "INNER JOIN `tbl_users` AS b ON a.fromId=b.id "; $sql .= "WHERE threadId=:id AND heldById=:heldById AND isDeleted=0 ORDER BY timestamp ASC"; $p_GetSingleMessage = $dbPrep->prepare($sql); function UnDeleteThread($threadId, $heldById){ global $dbPrep; $p_UnDeleteThread = $dbPrep->prepare("UPDATE `tbl_messages` SET isDeleted=0,isRead=0 WHERE threadId=:threadId AND heldById=:heldById"); $p_UnDeleteThread->execute(array("threadId"=>$threadId, "heldById"=>$heldById)); } function GetRecipients($sessId, $fromId, $toId){ $allParties = $sessId . "," . $fromId . "," . $toId; $arr = array_unique(explode(",", $allParties)); if (($key = array_search($sessId, $arr)) !== false) { unset($arr[$key]); } return implode (",", $arr); } function GetRecipientName($id){ global $dbPrep; $sql = "SELECT username FROM `tbl_users` WHERE id=:id"; $query = $dbPrep->prepare($sql); $query->execute(array("id"=>$id)); $row = $query->fetch( PDO::FETCH_ASSOC ); return $row["username"]; } function GetRecipientNames($recipients){ $all = explode(",", $recipients); $val = array(); foreach ($all as $a){ $val[] = GetRecipientName($a); } return $val; } $p_GetUnreadMessagesCount = $dbPrep->prepare("SELECT COUNT(*) FROM `tbl_messages` WHERE isRead=0 AND heldById=:heldById AND type='recv'"); $unreadMsgsCount = -1; function GetUnreadMessagesCount($uid){ global $unreadMsgsCount; global $p_GetUnreadMessagesCount; if($unreadMsgsCount == -1){ $p_GetUnreadMessagesCount->execute(array("heldById"=>$uid)); $unreadMsgsCount = $p_GetUnreadMessagesCount->fetch( PDO::FETCH_ASSOC ); $unreadMsgsCount = $unreadMsgsCount["COUNT(*)"]; } return $unreadMsgsCount; } function GetNewThreadId(){ global $dbPrep; $threadId = 1; $p_GetLatestThreadId = $dbPrep->prepare("SELECT MAX(threadId) FROM `tbl_messages`"); $p_GetLatestThreadId->execute(); $latestThreadId = $p_GetLatestThreadId->fetch( PDO::FETCH_ASSOC ); if($latestThreadId){ $threadId = $latestThreadId["MAX(threadId)"]+1; } return $threadId; } ?> if(isset($_REQUEST["mark_read"])){ if(isset($_REQUEST["message_all_toggle"])) foreach($_REQUEST["message_all"] as $m) SetNotificationRead($m, $session_user["id"], 1); elseif(isset($_REQUEST["message"])) foreach($_REQUEST["message"] as $m) SetNotificationRead($m, $session_user["id"], 1); else foreach($_REQUEST["message_all"] as $m) SetNotificationRead($m, $session_user["id"], 1); } if(isset($_REQUEST["mark_unread"])){ if(isset($_REQUEST["message_all_toggle"])) foreach($_REQUEST["message_all"] as $m) SetNotificationRead($m, $session_user["id"], 0); elseif(isset($_REQUEST["message"])) foreach($_REQUEST["message"] as $m) SetNotificationRead($m, $session_user["id"], 0); else foreach($_REQUEST["message_all"] as $m) SetNotificationRead($m, $session_user["id"], 0); } if(isset($_REQUEST["delete"])){ if(isset($_REQUEST["message_all_toggle"])) foreach($_REQUEST["message_all"] as $m) RemoveNotificationById($m, $session_user["id"]); elseif(isset($_REQUEST["message"])) foreach($_REQUEST["message"] as $m) RemoveNotificationById($m, $session_user["id"]); } } else { if(isset($_REQUEST["delete"])){ if(is_numeric($_REQUEST["delete"])){ UpdateMessageField(array("threadId"=>$_REQUEST["delete"], "heldById"=>$session_user["id"]), "isStarred", 0); UpdateMessageField(array("threadId"=>$_REQUEST["delete"], "heldById"=>$session_user["id"]), "isDeleted", 1); UpdateMessageField(array("threadId"=>$_REQUEST["delete"], "heldById"=>$session_user["id"]), "isRead", 1); }elseif(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 0); UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isDeleted", 1); UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 1); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 0); UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isDeleted", 1); UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 1); } } } if(isset($_REQUEST["messagestar"])){ if(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 1); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 1); } } } if(isset($_REQUEST["deletestarred"])){ if(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 0); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 0); } } } if(isset($_REQUEST["mark_unread"])){ if(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 0); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 0); } } } if(isset($_REQUEST["mark_read"])){ if(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 1); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 1); } } } } $details = isset($_REQUEST["details"])?$_REQUEST["details"]:0; $session_user = GetUserById($session_user["id"]);
Im working on my own (basic) forum sofware how would I determine if the user has read or unread the topic? (like SMF has a specific icon when viewing the forum/topic list which represents theirs unread topics within this forum). I just had a question for you guys. I am building a forum script and I'm currently stumped on the "show unread posts since last visit" feature. Not sure as to how to code it. Should I be using a mysql database to keep track of them or use cookies some how? Thanks in advanced! Hi
Could you please tell me how can i implement gmail api to send email to user contact on behalf of that user.
Using the attached code below I'm sending an HTML email using PHP. It works fine, except with Gmail. If the email is sent to a Gmail account the email contents are blank and sender is unknown. I've looked around and it seems there is some widespread issue but i haven't found an answer/solution. Any help or light shed on this would be great. <?PHP //lots of stuff before this including variable setting, which all are working properly $to = $email; $subject = 'Your claim is in process!'; $random_hash = md5(date('r', time())); $headers = "From: The Insurance Agency\r\nReply-To: info@XXXXXXXXXX.com"; $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; ob_start(); ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Dear <?PHP echo $fname?>, Thank you for submitting your claim on our website. We're sorry to hear about your loss on <?PHP echo $dateofloss ?>; our office has received your information and will contact you as soon as possible.Sincerely, Brian R Miller, Priciple --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <img src="http://beta.XXXXXXX.com/img/uniform/emailhead.gif" alt="" /> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:15px 0 5px 0;">Dear <?PHP echo $fname ?>,</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:0;">Thank you for submitting your claim on our website. We're sorry to hear about your loss on <?PHP echo $dateofloss ?>; our office has received your information and will contact you as soon as possible.</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:20px 0 0 200px;">Sincerely,</p> <p style="margin: 10px 0 0 200px;"><img src="http://beta.XXXXXX.com/img/uniform/briansig.gif" alt="" /></p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:0px 0 0 200px;">Brian R Miller, priciple</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:200px 0 0 0">This email has been sent by an automated service</p> --PHP-alt-<?php echo $random_hash; ?>-- <?PHP $message = ob_get_clean(); mail($to, $subject, $message, $headers); ?> I am writing a google contact API to get users contacts, I get everything back except for the email address of the contact. Anyone know how to get the contacts email address? Code: [Select] <?php class gdata{ private $headers; private $googleAuth = 'http://www.google.com/mate/feeds'; private $google = 'http://www.google.com/mate/feeds/contacts/default/full'; public $token; public function headers(){ $this->headers['GData-Version'] = '3.0'; $this->headers['Authorization'] = "AuthSub token=\"$this->token\""; $this->headers['Content-Type'] = "application/x-www-form-urlencoded"; $this->headers['Host'] = "www.google.com"; $this->headers['User-Agent'] = "php/".phpversion(); $this->headers['Accept'] = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"; $this->headers['Connection'] = "keep-alive"; } public function request_contacts($email){ $ch = curl_init(); $headers = array(); foreach($this->headers as $k => $v){ $headers[] = "$k: $v"; } $url = preg_replace("/\[email_address\]/", $email, $this->google); echo $url; curl_setopt($ch, CURLOPT_URL, $this->google); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $opt = curl_exec($ch); $xml = simplexml_load_string($opt); header("Content-type: text/plain"); foreach($xml->entry as $user){ //echo $user['link'] } print_r($xml->entry[5]); } public function auth(){ $next = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?a=getContacts'; header("Location: https://www.google.com/accounts/AuthSubRequest?next=".urlencode($next)."&scope=".urlencode($this->googleAuth)."&session=1&secure=0"); } } $gAPI = new gdata(); if($_GET['a'] == 'getContacts'){ $gAPI->token = $_GET['token']; $gAPI->headers(); $gAPI->request_contacts('untuned20@gmail.com'); }else{ $gAPI->auth(); } ?> i am using mail functions in php and i am sending mails but the mails are going to spam in gmail and for yahoo its going to inbox. my problem is i want to send the email to inbox only as most of them use gmail ....should i use any smtp or any other mail library functions? can anyone guide me? I'm using a simple form to grab an email address and send the person who signs up and automatic response. It was working for a while and now it's not. Not sure what happened. My hosting company told me to look into my headers. Can anyone help? Here is my code. Thanks, Code: [Select] <?php /* Set e-mail recipient */ $subject = "Sign Up"; $headers = "From: admin@xxx.com" . "\r\n" . "CC: admin@xxx.com"; /* Check all form inputs using check_input function */ $sign_up_email_address = check_input($_POST['sign_up_email_address'], "Please enter your email address."); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $sign_up_email_address)) { show_error("E-mail address not valid"); } /* Let's prepare the message for the e-mail */ $response_message = "Sample Message"; /* Send the message using mail() function */ mail($sign_up_email_address, $subject, $response_message, $headers); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <?php echo $myError; ?> Thank you, i have some code which sends a confrim link via the posted email. In hotmail it works fine, once the link is clicked they are confirmed but gmail adds %09 to the link making it break. example WHERE hash = their email hashed posted email = test@test.com confirm link(hotmail) confirm.php?email=HASH&o=test@test.com(works) confirm link(gmail)confirm.php?email=%09HASH&o=test@test.com(Doesnt work) anyone know why gmail does this? I'm using the php mail function and sending to Gmail accounts it shows "Unknown Sender" This is my header: Code: [Select] $headers = "From: XXXXX\r\nReply-To: XXXX@XXXXX.com"; $headers .= "\r\nContent-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit"; I read somewhere that removing the "\r" would work but no luck... any help would be awesome HI, i have a problem, a big one. I used a php script to send some info from my html forms to my gmail. So it functions easy, somebody fills out the form and he click send, after that, his information is sent to me on my gmail, and i can work with it later. Now stupid google have some new filters (from year 2014 ) and it treats some of those mails as spam. Code is written in the way that allows me to get those mails as it is sent from the user himself, from his email. Can anybody correct my script so it won't be treated as a spam, because i know it is possible but don't know how... here is the code - https://gist.github....67145d500c5cf47 // Receiving variables I'm building a PHP application that's connect to gmail and download the messages. I have an account that contains more than two millions messages and the PHP cannot connect to that account. What can I do? The error is: Mailbox has more messages (2004032) exist than maximum (1000000) $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); $emails = imap_search($inbox,'ALL'); if($emails) { $output = ''; rsort($emails); foreach($emails as $email_number) { $overview = imap_fetch_overview($inbox,$email_number,0); $message = imap_fetchbody($inbox,$email_number,2); $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'; $output.= '<span class="subject">'.$overview[0]->subject.'</span> '; $output.= '<span class="from">'.$overview[0]->from.'</span>'; $output.= '<span class="date">on '.$overview[0]->date.'</span>'; $output.= '</div>'; $output.= '<div class="body">'.$message.'</div>'; } echo $output; } imap_close($inbox); this code is not working, returns this when i try to execute. Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /Applications/MAMP/htdocs/gmailconnection.php on line 9 Cannot connect to Gmail: Can't open mailbox {imap.gmail.com:993/imap/ssl}INBOX: invalid remote specification Notice: Unknown: Can't open mailbox {imap.gmail.com:993/imap/ssl}INBOX: invalid remote specification (errflg=2) in Unknown on line 0 Any ideas?? Is there a working gmail connection/email retriever on this site? I couldnt find I've just setup an Apache server with a basic LAMP stack. We've decided to use Google Apps (gmail) as our mail server / host. So our ubuntu server is only serving up HTTP files. Because the server is not configured as a mail server, and we're using Gmail for our MX and mail servers, how do I go about using sending out emails via PHP on the Apache Box? I've tried installing Postfix, and configuring using this tutorial, and still a no go. http://www.blogternals.com/2009/04/30/postfix-google-apps-gmail-smtp-relay/ Any Ideas? Hi guys , my script works perfectly in Gmail however i now need it to work in Outlook , when the form is submitted i get this error.
2014-10-25 18:49:00 SMTP ERROR: Failed to connect to server: Connection timed out (110) 2014-10-25 18:49:00 SMTP connect() failed. Mailer Error: SMTP connect() failed.
<?php require("../lib/phpmailer/PHPMailerAutoload.php"); if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) { echo "No arguments Provided!"; return false; } $m = new PHPMailer(); $m->IsSMTP(); $m->SMTPAuth = true; $m->SMTPDebug = 2; $m->Host = "smtp.live.com"; $m->Username = "test@outlook.com"; $m->Password = "pass"; $m->SMTPSecure = 'tls'; $m->Port = 465; // ive also tried 587 $m->From = "test@outlook.com"; $m->FromName = "test@outlook.com"; $m->addReplyTo('test@outlook.com ','Reply Address'); $m->addAddress('test@outlook.com', 'Some Guy'); $name = $_POST['name']; $email_address = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $m->Subject = $subject; $m->Body = "You have received a new message. <br><br>". " Here are the details:<br> Name: $name <br> Phone Number: $phone <br>". "Email: $email_address<br> Message <br> $message"; $m->AltBody = "You have received a new message. <br><br>". " Here are the details:<br> Name: $name <br> Phone Number: $phone <br>". "Email: $email_address<br> Message <br> $message"; if(!$m->Send()) { echo "Mailer Error: " . $m->ErrorInfo; } else { echo "Message sent!"; return true; } ?> |