PHP isn't emailing form to the buisness owner?

My former boss wanted me to add a drop down menu to his request a quote form on his website. I have no experience with PHP and I’m not the webmaster of this site(I know I shouldn’t be doing this so please hold back on those comments and please try to help me). But he gave me the login info to his cpanel so I can change the files. All I needed to do was add a drop down menu to the form.

Looking over the PHP, it seemed pretty straightforward. This is what the PHP looked like. I only added two lines of code and now the owner can’t even receive this form from customers?

<?php 

//$to = "techlysesolutions@gmail.com";
// $to = "info@gilbertmovingandstorage.com";
$to = "gilbertmovingandstorage@gmail.com";

$fname = $_POST['element_1_1']; 
$lname = $_POST['element_1_2']; 
$email = $_POST['element_5']; 
$phone  = $_POST['element_6_1']; 
$message = $_POST['element_7'];

// pickup address  
$pick_add1 = $_POST['element_2_1'];
$pick_add2 = $_POST['element_2_2'];
$pick_add3 = $_POST['element_2_3'];
$pick_add4 = $_POST['element_2_4'];
$pick_add5 = $_POST['element_2_5'];
$pick_add6 = $_POST['element_2_6'];

// Drop Off Address address  
$drop_add1 = $_POST['element_3_1'];
$drop_add2 = $_POST['element_3_2'];
$drop_add3 = $_POST['element_3_3'];
$drop_add4 = $_POST['element_3_4'];
$drop_add5 = $_POST['element_3_5'];
$drop_add6 = $_POST['element_3_6'];

//Date
$month = $_POST['element_4_1'];
$day = $_POST['element_4_2'];
$year = $_POST['element_4_3'];
$ref = $_POST['element_4_4']; // I ADDED THIS LINE------------------------
$date = $month.'/'.$day.'/'.$year;



$subject = "Contact Inquiry";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From:".$email;
//$headers .= "BCC: admin@example.com";

echo $txt = '<table width="300">
                <tr><td></td><td>'.$fname.'&nbsp;'.$lname.'</td></tr>
                <tr><td></td><td>'.$email.'</td></tr>
                <tr><td></td><td>'.$phone.'</td></tr>

                    <tr><td style="font-weight:bold"></td></tr>
                <tr><td></td><td>'.$pick_add1.'</td></tr>
                <tr><td></td><td>'.$pick_add2.'</td></tr>
                <tr><td></td><td>'.$pick_add3.'</td></tr>
                <tr><td></td><td>'.$pick_add4.'</td></tr>
                <tr><td></td><td>'.$pick_add5.'</td></tr>
                <tr><td></td><td>'.$pick_add6.'</td></tr>

                    <tr><td style="font-weight:bold"></td></tr>
                <tr><td></td><td>'.$drop_add1.'</td></tr>
                <tr><td></td><td>'.$drop_add2.'</td></tr>
                <tr><td></td><td>'.$drop_add3.'</td></tr>
                <tr><td></td><td>'.$drop_add4.'</td></tr>
                <tr><td></td><td>'.$drop_add5.'</td></tr>
                <tr><td></td><td>'.$drop_add6.'</td></tr>

                <tr><td></td><td>'.$date.'</td></tr>
                <tr><td>Moving Date</td><td>'.$ref.'</td></tr> // I ADDED THIS LINE----------
                <tr><td></td><td>'.$message.'</td></tr>
        </table>';

mail($to,$subject,$txt,$headers);

As you can see I only added two lines. But I’ve since removed those lines when I found out I broke the whole thing, so it should be as if I never touched the file. Yet it still doesn’t work. I have no clue what to do.(I’m new to web dev so I’m not very technical) I’ve been told to check the php error log, except this creates a whole other problm. The two methods I tried didn’t pan out. I was told to find and edit the ini.php file and turn error logging on. I can’t find this file though the instruction were unclear on where it was, then someone told me

“if you’re on cPanel logging is probably already enabled. Look in your “logs” folder and you’ll likely see a file called “error_log”. If it’s not there, and you haven’t got access to a copy of php.ini, then ask your hosting support people to turn on PHP error logging for you.”

I found this file, but there is nothing in it. I tried viewing it in the cpanel and in notepad but its blank??

Please help guide me through this I’m on a time limit and I need to somehow fix this asap.

First check if this is giving any output $ref = $_POST['element_4_4']; and remove echo in front of $txt variable.

Thanks for coming to help, I really appreciate it. But I have no Idea how I would check to see any kind of output. I also wanna figure out why the whole thing is broke first before I try figuring out how to get the php to recognize and send the dropdown I added into the html because I removed what I added to the php once I found out the form was broke thereby returning the form to its original working state before I added those two lines, which should have fixed the issue right? Also that ‘echo’ was there when it was working before I messed with file so I’m sure it’s not that.

You can use var_dump() or print_r() for display output.

Example: before mail() put var_dump($txt); and this will show you output of that table if you access file directly from url like http://yourwebsite.com/file.php

Same you can did for $_POST data var_dump($_POST); before mail() function, and this will show you output of all data from form inputs in array so you can see if any input have missing.

Also add error_reporting(E_ALL); just after opening of php tag.

You posted that you added

$ref = $_POST['element_4_4']; 

but I don’t see a form element with the name “element_4_4”.

Are you sure the problem isn’t in the form?

If you temporarily change the code to

... 
$year = $_POST['element_4_3']; 
$ref = "initialized"; 
if ( !empty($_POST['element_4_4']) ) {
$ref = $_POST['element_4_4']; 
} 
$date = $month.'/'.$day.'/'.$year; 
... 

do you see “initialized”?

It’s probably not causing the problem, but there’s no need for it to be there.

First of all, where did you get the “original” PHP code from - the server by downloading it, or from a local saved copy somewhere? Are you absolutely certain that it’s the code that was running on the server before you changed anything? The only thing that would make any sense is if you’ve somehow picked up a copy that wasn’t the live one and didn’t work to start off with, unless there’s a typo you added.

Presumably you’ve checked that the “to” address is correct for the owner, as that looks like it’s been edited a few times.

This might be an issue:

$headers .= "From:".$email;

in that you’re sending your email “from” the customers email address, whatever they filled in on the form. A lot of commercial web servers (if they’re set up “properly”) won’t allow that, because you could be sending emails purporting to be from me, or anyone, and that’s quite a spammy thing to do. So mail servers will often only allow you to send from a domain that you own and have configured on that server to send mails. There are further measures, things like SPF, that check the registered mail servers on your domains DNS record, to further decrease the chances of Spam. As you’re sending to a gmail address, Google might do their own checking too.

Finally, this line

mail($to,$subject,$txt,$headers);

says that you’re using the built-in PHP mail() function to send your emails, which is often described as unreliable. I know you’re not experienced in PHP, but if you look a few topics further down there’s some reasonably complete code showing how to use PHPMailer instead, which is often said to be more reliable.

None of these are likely to have suddenly stopped your emails sending at the moment you
changed the code, though.

It’s here:

<div class="dropdown">
<label for="element_4_4" class="description">Referred by*</label>
<select name="element_4_4" id="dropdown">
<option value="Customer Referrel">Customer Referrel</option>
<option value="Home Advisor">Home Advisor</option>
<option value="Google">Google</option>
<option value="Facebook">Facebook</option>
<option value="Yelp">Yelp</option>
<option value="Postcard">Postcard</option>
<option value="Realtors">Realtors</option>
<option value="Reapeat Customer">Reapeat Customer</option>
</select>
</div>

Slightly o/t and again won’t stop the email sending, but that html table seems “off” to me. While there’s data it has two columns, but every now and again there’s a single row that just has a single column with a font-weight setting in it.

1 Like