This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

No emails sent via PHP Mail() function
#1
No emails sent via PHP Mail() function
I am building a webpage with a contact form that sends an email to me via the Mail() php function.

I can send/receive emails fine via Roundcube, but none are sent via this method.  

Here is my script:

contact page:

Code:
<form  action="mail_handler.php" method="post" class="col s12">
           <div class="row">
             <div class="input-field col s6">
               <input id="name" type="text" class="validate">
               <label for="name">Name</label>
             </div>
           </div>
           <div class="row">
             <div class="input-field col s6">
               <input id="email" type="email" class="validate">
               <label for="email">Email Address</label>
             </div>
             <div class="input-field col s6">
               <input id="telephone" type="tel" class="validate">
               <label for="telephone">Telephone Number</label>
             </div>
           </div>
             <div class="row">
               <div class="input-field col s12">
                 <textarea id="message" class="materialize-textarea"></textarea>
                 <label for="message">Breif description of work to be done.</label>
               </div>
             </div>
             <div class="row">
               <div class="input-field col s6">
                 <select>
                   <option value="" disabled selected>Choose the best way to contact you</option>
                   <option value="email">Email</option>
                   <option value="telephone">Telephone</option>
                 </select>
                 <label>Best Contact Method</label>
               </div>
               <div class="input-field col s6">
                 <button class="btn waves-effect waves-light" type="submit" name="action">Submit
                   <i class="material-icons right">send</i>
                 </button>
               </div>
             </div>
           </form>



php page:
Code:
<?php
if(isset($_POST['submit'])){
   $to = "myemailishere"; // this is your Email address
   $from = $_POST['email']; // this is the sender's Email address
   $name = $_POST['name'];
   $telephone = $_POST['telephone'];
   $contactmethod = $_POST['contactmethod'];
   $subject = "Form submission";
   $subject2 = "Copy of your form submission";
   $message = $name . " wrote the following:" . "\n\n" . $_POST['message'];
   $message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];

   $headers = "From:" . $from;
   $headers2 = "From:" . $to;
   mail($to,$subject,$message,$telephone,$contactmethod,$headers);
   mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
   echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
   // You can also use header('Location: thank_you.php'); to redirect to another page.
   // You cannot use header and echo together. It's one or the other.
   }
?>


Any ideas?  I'm not receiving any emails whether I specify the 'to' email as my personal email (hosted on protomail) or an email I have on round cube.
Reply
Thanks given by:
#2
RE: No emails sent via PHP Mail() function
If you send to mail@domain.com while domain.com setup in sentora it will likely send the email to local server.

Also can you test sending to gmail.com?

M B
No support using PM (Auto adding to IGNORE list!), use the forum. 
How to ask
Freelance AWS Certified Architect & SysOps// DevOps

10$ free to start your VPS
Reply
Thanks given by: kwongger
#3
RE: No emails sent via PHP Mail() function
(04-11-2016, 09:49 PM)Me.B Wrote: If you send to mail@domain.com  while domain.com setup in sentora it will likely send the email to local server.

Also can you test sending to gmail.com?

M B

Went ahead and tried sending to gmail, still no dice Sad
Reply
Thanks given by:
#4
RE: No emails sent via PHP Mail() function
can you check postfix queue to see where the file ended?

Also sending email that way can cause issues. As the sender may some time authorize few smtp servers to send on his behalf using SPF. Best is setting FROM as sever@domain.com.

M B
No support using PM (Auto adding to IGNORE list!), use the forum. 
How to ask
Freelance AWS Certified Architect & SysOps// DevOps

10$ free to start your VPS
Reply
Thanks given by: kwongger
#5
RE: No emails sent via PHP Mail() function
(04-12-2016, 12:33 AM)Me.B Wrote: can you check postfix queue to see where the file ended?

Also sending email that way can cause issues. As the sender may some time authorize few smtp servers to send on his behalf using SPF. Best is setting FROM as sever@domain.com.

M B

I'll check the postfix queue here in a sec.  I've changed the php to the below quoted code, but still no dice.

Code:
<?php
if(isset($_POST['submit'])){
   $to = "email@domain.com (not hosted on same server)";
   $to2 = $_POST['email'];
   $from = "email@domain.com (hosted on same server)";
   $name = $_POST['name'];
   $email = $_POST['email'];
   $telephone = $_POST['telephone'];
   $contactmethod = $_POST['contactmethod'];
   $subject = "Form submission";
   $subject2 = "Copy of your form submission";
   $message = $name . " wrote the following:" . "\n\n" . $_POST['message'];
   $message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];

   $headers = "From:" . $from;
   $headers2 = "From:" . $to;
   mail($to,$subject,$message,$telephone,$email, $contactmethod,$headers);
   mail($to2,$subject2,$message2);
   echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
   }
?>
Reply
Thanks given by:
#6
RE: No emails sent via PHP Mail() function
Alright.  I checked the postfix queue and I think that I've found the problem.

It looks like than an old domain name (that I no longer use or have) is configured somehow (see code below).

How would I remedy this?

Code:
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
3240B41965      833 Thu Apr  7 06:47:49  root@admin.olddomain.com
                                                 (mail transport unavailable)
                                        root@admin.olddomain.com

30F8B4196B     2961 Fri Apr  8 11:33:26  MAILER-DAEMON
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

5C9E841967     2899 Thu Apr  7 07:08:25  MAILER-DAEMON
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

5AC2D41962     2961 Thu Apr  7 11:33:25  MAILER-DAEMON
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

259FB419AE      833 Mon Apr 11 06:35:16  root@admin.olddomain.com
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

437F64197A      833 Sun Apr 10 06:54:14  root@admin.olddomain.com
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

43E8F41977     2961 Mon Apr 11 11:23:27  MAILER-DAEMON
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

9618841972     2899 Sat Apr  9 07:03:26  MAILER-DAEMON
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

A69D341943     2899 Mon Apr 11 07:13:26  MAILER-DAEMON
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

A68CE41976      833 Sat Apr  9 06:33:07  root@admin.olddomain.com
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

A473141978     2899 Sun Apr 10 06:58:26  MAILER-DAEMON
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

0F4D841945     2961 Sun Apr 10 11:43:27  MAILER-DAEMON
(delivery temporarily suspended: Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

71E1C418FB     2899 Fri Apr  8 07:08:26  MAILER-DAEMON
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

EF1BE4196F      833 Fri Apr  8 06:48:23  root@admin.olddomain.com
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com

EE32E40DE7     2961 Sat Apr  9 11:18:26  MAILER-DAEMON
(Host or domain name not found. Name service error for name=admin.olddomain.com type=AAAA: Host not found)
                                        root@admin.olddomain.com
Reply
Thanks given by:
#7
RE: No emails sent via PHP Mail() function
May be check postfix conf file if it's the default setup here.

M B
No support using PM (Auto adding to IGNORE list!), use the forum. 
How to ask
Freelance AWS Certified Architect & SysOps// DevOps

10$ free to start your VPS
Reply
Thanks given by: kwongger
#8
RE: No emails sent via PHP Mail() function
(04-12-2016, 05:16 AM)Me.B Wrote: May be check postfix conf file if it's the default setup here.

M B

I checked the config, and everything looks fine there.  I rebooted the server, cleared the mail queue, and tried a few more times.   The # of emails in the mail queue isn't increasing from 0 now.

edit: Thank you so much for your help by the way! I really appreciate it Smile
Reply
Thanks given by:
#9
RE: No emails sent via PHP Mail() function
Anyone else have any more ideas? I can't seem to find what's the problem Sad
Reply
Thanks given by:
#10
RE: No emails sent via PHP Mail() function
Still again the problem? Seem you said it was solved?
No support using PM (Auto adding to IGNORE list!), use the forum. 
How to ask
Freelance AWS Certified Architect & SysOps// DevOps

10$ free to start your VPS
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
Why can i not send emails from my site phabeon8 3 6 ,504 04-20-2021, 06:29 AM
Last Post: sparkrack
External mail client cannot connect to server iraqiboy90 2 6 ,236 02-28-2021, 11:34 AM
Last Post: iraqiboy90
Postfix mail.log to database stikekar 2 7 ,234 03-02-2019, 01:22 AM
Last Post: TGates

Forum Jump:


Users browsing this thread: 1 Guest(s)