473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to send email in php from localhost?

3
i am a beginner in php. i am making a small email sending script in php but no success till now. i am using XAMPP server. tried all the configurations settings and also with mercury email server in xampp but no success. Please help!!
Mar 26 '15 #1
4 2438
Exequiel
288 256MB
can you post your code on how you made your email sending?
Mar 26 '15 #2
amit08
3
Actually my concern is of sending mail to any of email client(e.g. yahoo or gmail) through my localhost. I am using xampp server. I did settings in php.ini and sendmail.ini but no success. Any how i am sending you my php code and i expect if you know any configuration settings of php.ini and sendmail.ini please suggest me.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $customeremail = $_POST['customeremail'];
  3. $message = $_POST['message'];
  4. $replywanted = false;
  5. if(isset($_POST['replywanted']))
  6.     $replywanted = true;
  7.  
  8. //build the text of email
  9.  
  10. $t = "you have received the message from ".    $customeremail . ":\n";
  11. $t = $t. $message. "\n";
  12.  
  13. if($replywanted)
  14.     $t = $t . "A reply was requested";
  15. else
  16.     $t = $t . "No reply was requested";
  17.  
  18. $headers = "From: sender@gmail.com";    
  19.  
  20. //send an email 
  21. $isSent =  mail("receiver@gmail.com", "Customer Message", $t, $headers);
  22.  
  23. if($isSent)
  24.     echo "thanks for sending the message";    
  25. else
  26.     echo "not sent";    
  27.  
  28. ?>
  29.  
Mar 27 '15 #3
jaroc
1
I am sorry, but some comments are in french.
Also, I have tested it with gmail and not yahoo.
I
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /* Setup email
  3.  
  4. Under PHP in XAMPP tool
  5. We must configure XAMPP parameters
  6.  
  7. The email server used to generate email is: gmail
  8.  You have to open and activate a parameter in google gmail, https://www.google.com/settings/security/lesssecureapps and select "activate"
  9.  (WARNING: this is not dramatic, because to use this server you must define the password in XAMPP.
  10.  
  11.  In the XAMPP tool
  12. C: \ xampp \ sendmail edit "sendmail.ini"
  13. Add two fields to the email address of your gmail account and password (WARNING: If this is not your PC that is dangerous)
  14.     auth_username=xxxx@gmail.com
  15.     AUTH_PASSWORD = yyyy
  16. Change the address and port for SMTP "smtp.gmail.com" and "587"
  17.     smtp_server = smtp.gmail.com
  18.     smtp_port = 587
  19.  
  20. C: \ xampp \ php edit "php.ini"
  21. Remove the ";" before "sendmail_path =" \ "C: \ xampp \ sendmail \ sendmail.exe \" -t "
  22. Add the ";" before sendmail_path = "C: \ xampp \ mailtodisk \ mailtodisk.exe"
  23.  
  24. !! it is mandatory to define a header "FROM" format xxx@yyy.zzz it is not necessary that this be your gmail address
  25.  
  26.  The appeal of this test is: http: // http: //localhost/yourdirectory/testemail.php
  27.  
  28. */ 
  29. ?>
  30.  
  31. <h1> test d'émission d\'email sous XAMPP </h1>
  32. <div>
  33.     <form method="post" accept-charset="utf-8" >  
  34.         <label for="to">Email</label>
  35.             <input type="email" name="to" id="to" value="<?php if (isset($_POST['to'])) echo $_POST['to']; ?>" />
  36.         <div>
  37.         <label for="subject">Sujet</label>
  38.             <input type="text" name="subject" id="subject"  value="<?php if (isset($_POST['subject'])) echo $_POST['subject']; ?>" />
  39.         </div>
  40.         <div>
  41.         <label for="message">Message (format HTML)</label>
  42.             <div>
  43.             <textarea name="message" id="message" rows="20" cols="50"><?php if (isset($_POST['message'])) echo $_POST['message']; ?></textarea>
  44.             </div>
  45.         </div>
  46.         <div>
  47.         <input type="submit" name="action" value="Envoyer" />
  48.         </div>
  49.     </form>
  50. </div>
  51.  
  52. <?php
  53. //print_r($_POST);
  54.  
  55. if (isset($_POST['action']) && $_POST['action'] == 'Envoyer') {
  56.     $send_error = "";
  57.     $required_fields = array('to', 'subject', 'message');
  58.  
  59.     foreach ($required_fields AS $v) {
  60.     //    echo 'champs : '.$v. ' valeur : ' .$_POST[$v].'<br>';
  61.         if (empty($_POST[$v])) { $send_error = "Un ou plusieurs champs sont vides, veuillez vérifier le formulaire."; }
  62.     }
  63.     if (empty($send_error)) {
  64.         $headers = "FROM:a@b.c";
  65.         //$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
  66.         extract($_POST);                    // pas nécessaire ici , cela vérifie le contenu de $_POST 
  67.         echo 'Email bien formulée et soumise avec les paramètres : <br>TO : ' .$to. '<br>SUBJECT : ' .$subject. '<br>HEADER : '. $headers. '<br>MESSAGE : '  .$message. '<br>';
  68.         if (!mail($to, $subject, $message, $headers)) { $send_error = "Erreur lors de l'envoi de l'email : voir les détails sous C:\xampp\sendmail\error.log";}    
  69.         //if (!true) { $send_error = "Erreur lors de l'envoi de l'email : voir les détails sous C:\xampp\sendmail\error.log";}    
  70.     }
  71.     else { 
  72.         echo '<div>Erreur : ' . $send_error . '</div>';
  73.     }
  74. }
  75. ?>
  76.  
  77.  
[/quote]
Apr 7 '15 #4
amit08
3
The email is still not received by the recipient. The error in error log file was Connection Closed Gracefully. I got this error many times before but failed to resolve. Please help.
Apr 8 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mahsa | last post by:
Hi I try to send email using this code it seems the code doesn't hhave any problem but it doesn't send any emailv do you have any idea? MailMessage objEmail = new MailMessage();...
9
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
1
by: Quentin Huo | last post by:
Hi: I tried to send email from an ASP.NET page through SMTP. But I always got the error: Server Error in '/' Application....
2
by: Ron | last post by:
hi guys, I am trying to send email using smtpMail. I can send emails inside the organization, but out of the organization I get an error "The server rejected one or more recipient addresses. The...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
16
by: =?Utf-8?B?Q2hlZg==?= | last post by:
I can use outlook2003 to send email,but I cann't use this code below to send email. Please help me to test this code and instruct me how to solve this problem in detail. software...
2
by: shahnawaz shaikh | last post by:
hi friends i want to send email thoruth stored procedure or i want to give functionality like alert which is send email automaticaly from database. just like a news or any ad email weekly or...
1
by: Rob Cazzell | last post by:
<body> <% Dim EMailFrom As String= "?" Dim EMailTo As String="?" Dim EMailSubject As String="?" Dim EMailBody As String="?" Dim MySmtpClient As New_ ...
0
by: Mike Massaro | last post by:
Hello everyone, I'm new to PHP and creating an advertising website for massage therapists. On the profile page I'm creating a button so anyone can click on to send the advertiser an email. I...
0
by: blck | last post by:
Hi, I rented a host. At localhost, i can control send email from this host to my email. However, when i hosting, it appears the below error: The SMTP server requires a secure connection or the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.