-1

I have an html form with information being sent to this script and everything is working perfectly, except the email being sent... It appears to send (if statement goes through). but I don't receive anything. A few days ago I was receiving emails, where all data would be "Array[]", but now for some reason it's not working.

<?php
echo "<link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>";

if (!empty($_POST) && $_POST['email-address'] != null)
{
    $inquireType = $_POST['inquiry-type'];
    $firstName = $_POST['first-name'];
    $lastName = $_POST['last-name'];
    $email = $_POST['email-address'];
    $businessName = $_POST['business-name'];
    $information = $_POST['extra-information'];

    $message = "" . $inquireType . ' INQUIRIE FROM: ' . $firstName . ' ' . $lastName . "\r\n" .
        'Email: ' . $email . "\r\n" .
        'Business Name: ' . $businessName . "\r\n" .
        'Additional Information: ' . $information;

    $headers = "From: " . strip_tags($_POST['email-address']) . "\r\n";
    $headers .= "Reply-To: ". strip_tags($_POST['email-address']) . "\r\n";
    $headers .= "CC: bud@budbroesky.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n";

    mail('myemail@gmail.com', "Inquirie", $message, $headers);

    if (mail('myemail@gmail.com', 'Inquirie From ' . $firstName, $message, $headers))
    {
        echo "<div style='position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: green;'><br><br><p align='center'><font size='5rem' face='Montserrat' color='white'>Inquiry Successfully Sent! Expect a reply from me shortly.";
    }
    else {
        echo "<div style='position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: red;'><br><br><p align='center'><font size='5rem' face='Montserrat' color='white'>Inquiry Not Sent, something must have went wrong...";
    }
}
else {
    echo "<div style='position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: darkred;'><br><br><p align='center'><font size='5rem' face='Montserrat' color='white'>Inquiry Not Sent, something must have went wrong...";
}

 ?>
  • Did you check your Spam folder? – Samir Selia Feb 13 '16 at 05:24
  • R u getting Inquiry Not Sent, something must have went wrong??? – devpro Feb 13 '16 at 05:25
  • I constantly check my Spam folder, and no, it's showing that the email is going through... – BudBroesky Feb 13 '16 at 05:27
  • And u r getting Successfully Sent! Expect a reply from me shortly.?? – devpro Feb 13 '16 at 05:28
  • 2
    There are several things that could go wrong with `mail()` function. Refer this SO question, [http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail](http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – Rajdeep Paul Feb 13 '16 at 05:35
  • The actual issue was my hosting service required the $header's "From" to be a registered email (i.e. contact@yourdomain.com). My code is now working perfectly! budbroesky.com – BudBroesky Feb 18 '16 at 14:13

2 Answers2

0

The variable $headers is a string and you are using implode("\r\n", $headers) while sending email. This will throw a warning.

Replace implode("\r\n", $headers) with $headers since you are already concatenating \r\n while preparing the header string.

Samir Selia
  • 7,007
  • 2
  • 11
  • 30
0

I think it's because you have not provided credentials for email account. I have used the code below (in C#) in my app. I wish it can help you.

            //Configure an SmtpClient to send the mail.
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.EnableSsl = true; //only enable this if your provider requires it
            //Setup credentials to login to our sender email address ("UserName", "Password")
            NetworkCredential credentials = new NetworkCredential("mymail@gmail.com", "mypassword");
            client.Credentials = credentials;
Ladmira
  • 1
  • 1