PHP - Setting Smtp In Php.ini To Make Mail() Function Work
ok guys, another issue for me i cannot find an answer for. according to this thread: https://stackoverflow.com/questions/8803994/php-mail-not-working-for-some-reason, mail() doesn't work when smtp is not configured properly. I checked my server files and I do not have a .ini file. am I spose to have one by default? and, according to this question in the godaddy community: https://www.godaddy.com/community/Using-WordPress/PHP-ini-how-to-make-changes-using-cPanel/td-p/119704, configuration of PHP in general should be done in the .user.ini file instead of in php.ini. the following code, which is what I have now, results in no mail being sent to my address so either my code is wrong or my configs are not set properly I'm guessing: if( empty($errors)) { $to = '$myemail'; $email_subject = "Demo Request Submitted"; $email_body = "A demo request was submitted through your website with the following information:" . "Contact Name: " . $contact . " </br>" . "Company: " . $company . " </br>" . "Email: ". $email . " </br>" . "Phone: " . $phone . " </br>" . "Best Time to Contact: " . $best_time_to_contact . " </br>" . "Message: " . $message; $headers = "From: " . $myemail . "\n"; $headers = "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"; mail($to, $email_subject, $email_body, $headers); echo "Your demo request has been sent."; } else { echo $errors; } also, in the stackoverflow article I mentioned above, one of the responders suggests using PHPMailer as a better way to send mail using PHP. Is that true? I've always used mail() in the past and I've never been let down in terms of a message *not* being sent. PHP.net says the same thing as the response from stackoverflow as well. thanks! Edited November 21, 2019 by ajetrumpetSimilar Tutorials$to=sammieave@ave.com,samuel@ave.com; $subject = "New Event Logged"; $message = "Test"; $headers = "From: Samuel<sammieave@ave.com>;\r\n"; $headers .= "Content-Type: text/html"; mail($to,$subject,$message,$headers); I am having the above code but unfortunately the error I am getting is: Warning: mail() [function.mail]: SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in C:\xampp\htdocs\CRM\support\mailer.php on line 139 I am trying to integrate php mail script on my website Logon Utility but getting error such as :
<?php
// your secret key
if ($_POST["g-recaptcha-response"]) {
$pcount=0; $from = "".$name." <".$_POST['email'].">"; $to = "info@yourdomain.com"; $subject = "Mail from Logon Utility";
while (list($key,$val)=each($_POST))
if ($pcount > $gcount)
}
$headers2 = array ('From' =>$from2 ,
$smtp = Mail::factory('smtp',
Hi PHP Developers, I am trying to integrate php mail script on my website mysmsmantra but getting error such as : Fatal error: Uncaught Error: Call to undefined method PEAR_Error::send() in /home/website/public_html/mysmsmantra.com/sendmail2.php:99 Stack trace: #0 {main} thrown in /home/website/public_html/mysmsmantra.com/sendmail2.php on line 99 I am using below code to send mail :
<?php
// your secret key
if ($_POST["g-recaptcha-response"]) {
$pcount=0; $from = "".$name." <".$_POST['email'].">"; $to = "info@yourdomain.com"; $subject = "Mail from mysmsmantra";
while (list($key,$val)=each($_POST))
if ($pcount > $gcount)
}
$headers2 = array ('From' =>$from2 ,
$smtp = Mail::factory('smtp',
Edited December 8, 2020 by mysmsmantra Hello All,
I am strugling with embending standard smtp code within the one I have. As I am using PHP ocassionaly I have problem with this.
My code is to use mail function to send email through an form with email server installed on host system where the form and server are together.
I want this code to adapt to sth that can login to google account and use google external smtp protocol to send the content of the form defined in $headers
The problem is I am using self generated captcha that validates if the email is sent and all fields are filled (currently under tests what should be filled and not filled) and it works fine
This is my code that works on a local host server:
//Set up the email headers
//Set up the email content
// Required Fileds Validation
And would like sth like this in place of $mailer , but my way is not working The code I thought would be embeded into $mailer $mail->isSMTP();$mail->Host = 'smtp.googlemail.com'; //gmail SMTP server $mail->SMTPAuth = true; $mail->Username = 'GMAIL_USERNAME'; //username $mail->Password = 'GMAIL_PASSWORD'; //password $mail->SMTPSecure = 'ssl'; $mail->Port = 465; //SMTP port Any idea how to adapt it to my code are welcomed and appreciated,
Thanks
Edited April 29, 2019 by slawotrend I am having an issue with a support ticket program. I have added a feature to this program that allows my staff members to add multiple users to a ticket. The problem I am having because I am new to PHP is how do I email the users when they have been added to the ticket. Below is the code I am using for add user. If someone could look at it and help me figure out how to get this to email the user when they are added to the support ticket that would be great. I have been struggling with this for alot of nights and just cant figure it out. Code: [Select] <?php require "../conf/conn.php"; require "../conf/conf.php"; require "session.php"; ?> <html> <head> <title><?php echo "$c_title - Add User"; ?></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <STYLE type="text/css"> <?php include('../style.php'); ?> </STYLE> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function dele(assigned_user,username,ticket_id,id) { var assigned = document.getElementById('assigned_user').value; if(assigned_user==assigned) { alert("You Can't Delete the user '"+username+"'\nUsername assigned for the ticket '"+ticket_id+"'"); } else { if(confirm('Are you sure to delete?')) window.location.href = "adduser.php?action=delete&user_id="+assigned_user+"&ticket_id="+ticket_id+"&ticid="+id; } } // End --> </script> </head> <body> <?php $ticket_id = $_GET['ticket_id']; if(isset($_GET['action'])) { if($_GET['action']=='delete'){ if(isset($_GET['ticid'])) { $tid = $_GET['ticid']; $query_user ="DELETE FROM support_users WHERE id='$tid'"; $result=mysql_query($query_user); echo $_SESSION['successMsg'] = "<b>User Deleted From the ticket '$ticket_id'</b>"; } } } if(!empty($_POST)) { $date = date('Y-m-d H:i:s'); $puid = $_POST['username']; if($puid!='') { mysql_query("INSERT INTO support_users (id,user_id,ticket_id,assign_date) VALUES ('','$puid','$ticket_id','$date')") or die("<B>Error ".mysql_errno()." :</B> ".mysql_error().""); $_SESSION['successMsg'] = "User Added !"; } } $query_user ="SELECT SU.id,SU.user_id,SU.ticket_id,SU.assign_date,U.user,U.name,U.email FROM support_users AS SU LEFT JOIN users AS U ON SU.user_id=U.id WHERE ticket_id='$ticket_id';"; $result1=mysql_query($query_user); $user_arr = array(); while($userrow1 = mysql_fetch_array($result1)) { $user_arr[] = $userrow1['user_id']; } $result=mysql_query($query_user); $query_user ="SELECT * FROM support WHERE Ticket='$ticket_id';"; $support_result=mysql_query($query_user); $support = mysql_fetch_array($support_result); /* $query_user ="SELECT * FROM users WHERE Ticket='$ticket_id';"; $support_result=mysql_query($query_user); $support = mysql_fetch_array($support_result);*/ if(isset($_SESSION['successMsg'])) { if($_SESSION['successMsg']=="") { echo $_SESSION['successMsg']; $_SESSION['successMsg'] = ""; } } ?> <form method="post" action=""> <table width="400" border="0" align="center" cellspacing="1"> <tr> <td colspan="4" class="submenu"> Ticket ID <?=$ticket_id?> </td> </tr> <tr align="center"> <td colspan="4" class="submenu"> Add Users </td> </tr> <tr align="center"> <td class=""> Select User </td> <td> <select name="username"> <option value="">[--Select User--]</option> <?php $query_user1 ="SELECT * FROM users WHERE level = '3' AND active <> '0' AND validated ='1' order by name"; $result1=mysql_query($query_user1); while($userrow1 = mysql_fetch_array($result1)) { if(!in_array($userrow1["id"],$user_arr)) { $tempuser=$userrow1["user"]; ?> <option value="<?php echo $userrow1["id"];?>"<?php if($row_user[user]==$tempuser){echo " selected ";}?>><?php echo "$userrow1[user] ($userrow1[name] )"; ?></option> <?php } } ?> </select> <input type='submit' value='Add'> </td> </tr> </table> </form> <table width="400" border="0" cellspacing="0" cellpadding="0" align="center" class="border"> <tr> <td> <table width="400" border="0" align="center" cellspacing="1"> <tr align="center"> <td colspan="4" class="submenu"> Assigned Users <input type='hidden' id='assigned_user' name='assigned_user' value="<?=$support['user_id']?>"> </td> </tr> <tr> <td class="descrip">User</td> <td class="descrip">Name</td> <td class="descrip">Email</td> <td class="descrip">Actions</td> </tr> <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td class="dat"><a href="#" onClick="sendValue(<?php echo "'".$row[user]."'"; ?>);"><?php echo $row[user]; ?></a><?php if ($row["active"] == 2) echo "<font size=1 color=#FF0000> (Suspended)</font>"; ?></td> <td class="dat"><?php echo $row["name"]; ?></td> <td class="dat"><?php echo $row["email"]; ?></td> <td class="dat"><img src="../images/delete3.gif" /> <a href="javascript:dele('<?=$row["user_id"]?>','<?=$row["user"]?>','<?=$row["ticket_id"]?>','<?=$row["id"]?>');">Delete </a></td> </tr> <?php } ?> <tr align="center"> <td colspan="4" class="submenu"> <?php if ($numpage>1) { pagenav(); } else { echo " "; } ?> </td> </tr> </table> </td> </tr> </table> <br><table align="center"><tr><td><a href="javascript:window.close();">Close Window</a></td></tr></table> </body> </html> Thanks in advance for any help... Hey guys.
I am currently hosting my website on my own dedicated server, and i am trying to use the mail() function, but for some reason it doesn't send the email.
This is my php code:
the *** are real addresses.
The from is admin@host.com
<?php $to = "****"; $subject = "Test mail"; $message = "email message."; $from = "***"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> Edited by Tzahi_ben_artzi, 02 October 2014 - 02:44 PM. Hello, Something that's been really bugging me the last days is a problem in PHP, the mail(); function, so here goes. First, my script: Code: [Select] $to = "valid@hotmail.com"; $subject ="contact form"; $body = "Hello, you have been contacted"; $from = "$_POST['email']; $headers = 'From : valid@hotmail.com'."\r\n".'Reply-To: valid@hotmail.com'; if (mail($to, $subject, $body, $headers)) { echo "worked"; } else { echo "didn't work"; } I'm using Ubuntu linux and have set up an SMTP server like so: Code: [Select] sudo apt-get install postfix And configured it. I have also forwarded TCP port 25 to the server. Problem: I run the script and it echos 'worked', meaning that there was no error. However, I don't get a mail sent into my inbox. Thanks in advance, Drmota This topic has been moved to Installation in Windows. http://www.phpfreaks.com/forums/index.php?topic=318822.0 Does any know how to set SMTP Mail Configuration using the gmail account? Hi, Can someone please post very straight forward lines for sending email (no attachment nothing, just a subject and one line text in body) using google smtp (ssl://smtp.gmail.com) without any help of some classes like PHPmailer? Thanks, I'm getting the following error: Quote Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in (file path) I'm sure this error has been posted before, but I've searched and can't find a solution. I'm running XAMPP 1.7.3 with the Mercury/32 mail server v.4.72, which IS set to permit SMTP relaying of non-local mail. Is there anything I can change in php.ini, or anywhere else for that matter, to solve this? I'm tearing my hair out with this... If I can just get it to send out this email, my project is finished, but I've been wrestling with this mail() function for about 3 hours. Any help would be appreciated. Hello i m newbie to PHP. I am trying to host the website on my laptop but due to some configuration i cant send the emails through php script. I am trying send mail through mail() but not able to sent mail. heres the code: $to = "jwalant.baria@gmail.com"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } Output: Message delivery failed.. I read the previous post here. but I am not able to figure out what to do about it. Can anyone tell me what setting i do in my php.ini? or any other that necessary settings require for this. i don't have SMTP server on my laptop so is there any method from which i can setup the SMTP server on laptop.? I use apache HTTP 2.2 and PHP 5.3.4 Rest of the website working correctly but only mail not working. TY..!! I need to change the timestamp of the mail sent through the smtp . right now the mail i receives is 7 hour ahead, when i run the script through browser the time displayed is ok, but when i run it by cron job its always 7 hour ahead. my script is like this $from = "From <from@domain.com>"; $to = "Receiver <to@domain.com>"; $subject = "Hi! Cron job timestamp test"; $body = "Hi,\n\n test msg and date is ?".date("Y-m-d H:i:s"); $host = 'host'; $username = 'username'; $password = 'password'; $port = "25"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } Hi I really would appreciate if some phpfreak can help me with this please . I need to my contact page send emails so that when recipient receives it, it comes with the correct domain (same as the web address) it is coming from rather than the server name. At the moment they are coming as abcd20@elessar.nocdirect.com and would like them come as abcd20@myowndomain.com (lets say my password for that email is 'zzzaaa' and the domain was myowndomain.com ) Here is my email contact php script which works fine and hopefully would not have to change too much. My Contact form is posting to 'send.php' . On top of my contacts page there is a js script for 'jquery.js' and some jQuery stuff for validation.. Have seen many scripts but could not adapt to my existing send.php script. Can you please help? ------ Content of 'send.php' ----------------------------------- <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','phone','message'); $required = array('name','email','phone','message'); $your_email = "abcd20@myowndomain.com"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "New message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?> -------------------------------------------------------------------------------- Hi, I am looking for a script which will help me to send prebuilt e-mail to people with attachments. Something like this >>> To : [ ________________ ] <--Textbox Subject : [ _____________] <-- Subject Main body : [___________________] [___________________] [___________________] [___________________] [___________________] <-- with html [ Submit ] I would like to attach 5 photos in .jpg which are hosted on server. Now everything is prebuilt except "To : " as peoples email ID will always change. When Submit is clicked, main body Data and attachment will be sent to "To :" person with SMTP and not php mail() Well I have covered till sending mail with SMTP, using PEAR PHP, but I am not able to send attachments i.e. photos. I have 2 pages, index.php - 1st page which includes form and button sendmail.php - Includes all function and main data Following is the code of sendmail.php <?php include("Mail.php"); include('Mail/mime.php'); $to = $_POST["to_textbox"]; $from = $_POST["from_textbox"]; $subject = $_POST["subject_textbox"]; $message = $_POST["content_textbox"]; $headers = "From: " . $from . "\r\n"; /* SMTP server name, port, user/passwd */ $smtpinfo["host"] = "xbc.pqr.com"; $smtpinfo["port"] = "465"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "user"; $smtpinfo["password"] = "pass"; /////////////////Attachments Section Start ////////////// $file = '/home/xyzuser/public_html/xbx.pqr.com/mail1/img/linux_logo.jpg'; $crlf = "\n"; $mime = new Mail_mime($crlf); $mime->addAttachment($file, 'image/jpeg'); //do not ever try to call these lines in reverse order $attach= $mime->get(); ///////////////Attachment Section ends //////////////// /* Create the mail object using the Mail::factory method */ $mail_object =& Mail::factory("smtp", $smtpinfo); /* Ok send mail */ $mail_object->send($to, $headers, $subject, $message, $attach); ?> Now problem is, it is not sending linux tux logo from "img" folder i.e. mail sent with just text from previous page's textbox. It is not handling with attachment i.e. photo, what to do ? Thanks to http://pear.php.net/manual/en/packag...me.example.php How to add SMTP authentication for PHP mail form which is using POST function... This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=307948.0 this issue is not about core php hacking, but I guess this topic fits here best. I want to make php mail() function send emails using remote smtp server. I want to force this to all mail() users at my servers. However I use linux php so I cant specify remote smtp in php.ini cause php passes emails directly to sendmail/qmail ... (ps. I dont need script to use with remote smtp by socket connections, i want to make MAIL() do it so my users dont have to change anything at their source). So what I need is a) MTA like sendmail that actualy dont send mails to repicients, but it transfers it to remote mta-smtp (ps. I dont want relay, cause I dont want relaing to be visible in source of message) or b) some core hack-mod to make php mail() with php.ini work like on windows - not with sendmail/qmail but with socket connection to smtp. Any ideas.. I guess not This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=351914.0 Hello Everyone I have written a simple mail function to be emailed to a certain person on submission. On submission they would also like to have attachments sent to them. I got the email being sent but I can;t get the attachments to work. I have read several different examples and tutorials and none of them work. This is my code so far without any code for file attachment <?php $project_name = $_POST['project_name']; $needed = $_POST['date_needed']; $submitted = $_POST['date_submitted']; $department = $_POST['department']; $contact = $_POST['contact_person']; $extension = $_POST['extension']; $project_type = $_POST['project_type']; $published = $_POST['date_last_published']; $description = $_POST['description']; $color = $_POST['color']; $pdf = $_POST['pdf_needed']; $web = $_POST['web_needed']; $quanity = $_POST['quanity']; $email = "mdmartiny@sc4.edu"; $subject = "SC4 Graphics Design Service Request Form"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $message = "<html><body> <table width=\"100%\" border=\"0\" cellspacing=\"5px\" > <tr><td></td> <td>Project name: $project_name</td> <td></td> <td>Date needed by: $needed</td> </tr> <tr> <tr> <td></td> <td colspan=\"3\" align=\"left\" valign=\"top\"><strong><font size=\"+1\">Submitted to graphic designer</font></strong></td></tr> <tr><td height=\"25\"></td><td>Date $submitted</td><td>Department $department</td><td></td></tr> <tr><td height=\"25\"></td><td>Contact Person $contact</td><td>Extension $extension</td><td></tr> <tr><td height=\"25\"></td><td>Type of project $project_type</td><td colspan=\"2\">Approximate date of last publication $published</td></tr> <tr><td height=\"25\"></td><td colspan=\"3\">Project description/special instructions</td> <tr><td></td>><td colspan=\"3\">$description</td></tr> <tr><td height=\"25\"></td><td>Color $color</td><td>PDF needed $pdf</td><td>Website update needed $web</td></tr> <tr><td ></td><td>Estimated print quanity $quanity</td><td></td><td></td></tr> <tr> <td colspan=\"4\" align=\"left\" valign=\"top\"><hr height=\"5\"/> <strong><font size=\"+1\">Graphics office use only</font></strong></td> </tr> <tr> <td height=\"25\" width=\"2%\"> </td> <td width=\"34%\">Print Shop Color copier</td> <td colspan=\"2\">Print Vendor_______________________________________</td> </tr> <tr> <td height=\"25\"> </td> <td><strong><font size=\"+1\">Project tracking</font></strong></td> <td> </td> <td> </td> </tr> <tr> <td height=\"25\"> </td> <td colspan=\"3\">Received by graphic designer_______________________ Date _______</td> </tr> <tr> <td height=\"25\"> </td> <td colspan=\"3\"> <table width=\"100%\" height=\"35\"> <tr> <td>Approved by executive director__________ Date_________</td><td><input type=\"checkbox\"> Revisions needed<br /><input type=\"checkbox\"> Revisions made ______ Date_______</td><tr> </table> </td> </tr> <tr> <td height=\"25\"> </td> <td colspan=\"3\">Completed and spell checked by graphic designer___________________________ Date__________</td> </tr> <tr> <td> </td> <td align=\"center\" colspan=\"3\"> <table cellpadding=\"10px\" cellspacing=\"0\" border=\"1\" width=\"100%\"> <tr bgcolor=\"#CCCCCC\"> <td> <table> <tr> <td> Proofread by marketing coordinator __________ Date__________</td> </tr> <tr> <td> Proofread by secretary __________ Date__________ </td> </tr> </table> </td> <td> <input type=\"checkbox\"> Revisions needed <br> <input type=\"checkbox\"> Revisions made ____ Date_____ </td> </tr> </table></td> </tr> <tr> <td></td> <td colspan=\"3\"> <table width=\"100%\" height=\"75\"> <tr> <td>Proofread by executive director______ Date______ </td><td><input type=\"checkbox\"> Revisions needed<br /> <input type=\"checkbox\"> Revisions made ______ Date_______</td> </tr> </table> </td> </tr> <tr> <td></td> <td colspan=\"3\"> <table width=\"100%\" height=\"75\"> <tr> <td> Approval by requesting department __________ Date_________ <br /> <strong><font size=\"-1\">(Include all paperwork when returning)</font></strong></td><td><input type=\"checkbox\"> Revisions needed<br /><input type=\"checkbox\"> Revisions made ______ Date_______</td> </tr> </table> </td> </tr> <td></td height=\"25\"> <td colspan=\"3\">Final approval by executive director _________________________________________ Date_________ </td> </tr> <tr> <td height=\"75\"></td> <td><input type=\"checkbox\"> Printed ____ Date _____</td> <td colspan=\"2\"><input type=\"checkbox\"> PDF created _____ Date _____<br /> <input type=\"checkbox\"> Website updated _____ Date _____</td> </tr> </table>"; $message .= "</body></html>"; mail($email, $subject, $message, $headers, "From: $email"); echo "The email has been sent."; ?> |