Email isn't sending (PHP mail)

Status
Not open for further replies.

elitepet

New Member
Messages
24
Reaction score
0
Points
1
I've made a contact form on my client's site, but the email that is supposed to send to him isn't sending with the PHP mail function. The second email, which is a confirmation email to the person that submitted the form, works. But the one that is supposed to send to my client doesn't.

Account username: elitepet

Here is the code:

PHP:
$to = "email1@email.com, email2@email.com"; // changed emails for privacy reasons
$bcc = "email@email.com";
$subject = "Contact Form Submission from $name";
$date = date("l, F j, Y \a\\t g:i A");
$body = "There has been a new contact form submission on the Elite Pet Stop Fencing website. 

Name: $name
Email Address: $email
Phone Number: $phone
Submitted: $date

Message:

$message

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
To send a reply to $name, just reply to this email notification or compose a new email to $email.";

$headers = 'Content-type: text/plain' . "\r\n" .
'From: Elite Pet Stop Fencing <noreply@elitepetfence.com>' . "\r\n" .
'Reply-To: '.$email . "\r\n" . 
'Bcc: '.$bcc . "\r\n" . 
'MIME-Version: 1.0' . " \r\n" . 
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $body, $headers) or die("Error: Could not send email.");

Does anybody know why it won't send? There aren't any errors. The other one sends fine, but this one doesn't. I've checked the spam folder, etc. and it's not in there. It sent several days ago but it hasn't been working now.

Thank you in advance.
 

sicelx10

Member
Messages
126
Reaction score
2
Points
18
You cant declare the variable "$to" in that way, you are writing 2 emails in the same variable, the parameters just need 1 email address. If you want to send multiple emails for different email adresses, you can:
1.-Make another mail() function to send a mail for each email adress or
2.- You can make an array in the same variable and use the "implode()" function like this: http://stackoverflow.com/questions/4506078/php-send-mail-to-multiple-email-addresses or
3.- If you are obtaining email addresses from a database, i recomend you to use a while loop, like this: http://www.dynamicdrive.com/forums/...-to-use-php-to-send-multiple-emails-at-a-time
 

elitepet

New Member
Messages
24
Reaction score
0
Points
1
Thanks for your reply!

But according to the PHP docs, you can: http://php.net/manual/en/function.mail.php

Also, that solution on that Stack Overflow question does the same thing (it creates a comma separated list). It's just a little nicer because the emails are inputted into an array first and then the array values are imploded into a string (email addresses separated by commas).

The mail sending issue must be to do with the SMTP server. I hope I can get this resolved soon :/

I wonder if it's being marked as "spam" by the system?
 

sicelx10

Member
Messages
126
Reaction score
2
Points
18
*In the "$subject" you have to concatenate like this:
$subject = "Contact Form Submission from".$name; (Also, Where is "$name" declared o_O?)
*In the "$body" variable is missing a quotation mark at the end of that variable
 

elitepet

New Member
Messages
24
Reaction score
0
Points
1
*In the "$subject" you have to concatenate like this:
$subject = "Contact Form Submission from".$name; (Also, Where is "$name" declared o_O?)
*In the "$body" variable is missing a quotation mark at the end of that variable
With double quote strings you can concatenate by just putting the variable within it because double quoted strings are parsed. And the body variable is closed under the dashed line.

That would make the string "mail1@example.commail2@example.com".

I'm pretty sure it isn't a PHP error because the rest of the code executes properly and the info is inserted into the database (which is after the mail code).

Do you know if there is a way to check if the system is marking it as spam or something?
 

sicelx10

Member
Messages
126
Reaction score
2
Points
18
Your problem is with your script, because i have my own script to send mails and i just send 2 mails in arrays(Outlook and Gmail) with my code and was successfully send. I tested your code you posted and no e-mail was received.

"Do you know if there is a way to check if the system is marking it as spam or something?"
Nope :/
 

sicelx10

Member
Messages
126
Reaction score
2
Points
18
I have the solution, the variable "$to" is the problem, i just put one mail and was sent, please read the first comment i posted.
 

elitepet

New Member
Messages
24
Reaction score
0
Points
1
I have the solution, the variable "$to" is the problem, i just put one mail and was sent, please read the first comment i posted.
Why is that the problem? According to the PHP manual and email standards, to send emails to multiple addresses you use a comma-separated list.

I just tried it with one email address and it didn't work. There must be something wrong with my account or x10's system won't send it because it thinks that it is spam for some reason (that actually happened before a while back). One of the emails actually sends (the email confirmation to the user that submitted the form) but the most important email of all - the one that is supposed to send to my client - doesn't send.
 

elitepet

New Member
Messages
24
Reaction score
0
Points
1
Your problem is with your script, because i have my own script to send mails and i just send 2 mails in arrays(Outlook and Gmail) with my code and was successfully send. I tested your code you posted and no e-mail was received.

"Do you know if there is a way to check if the system is marking it as spam or something?"
Nope :/

This:
PHP:
$emails = array("email@hello.com", "email2@hello.com");
$to = implode(",", $emails);

Is the same thing as this:
PHP:
$to = "email@hello.com,email2@hello.com";

With both of those pieces of code, the $to variable is equal to "email@hello.com,email2@hello.com".
 

elitepet

New Member
Messages
24
Reaction score
0
Points
1
Did you try sending the same message but with your code? I'm starting to think it's something to do with the subject and/or body text. I'm thinking the system is marking the message as spam for some reason. It happened before and an administrator fixed it for me.
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
You cant declare the variable "$to" in that way, you are writing 2 emails in the same variable, the parameters just need 1 email address...
I use more then one Email address in the "$to" (like the OP) and is working in my account
 

sicelx10

Member
Messages
126
Reaction score
2
Points
18
Did you try sending the same message but with your code? I'm starting to think it's something to do with the subject and/or body text. I'm thinking the system is marking the message as spam for some reason. It happened before and an administrator fixed it for me.
I tried, and the first message was received in the junk folder, the second email got received in the main inbox, hmmmmm... weird.
 
Status
Not open for further replies.
Top