PHP Mail function and foreign domains - php

PHP Mail function seems to have issues sending emails TO: #domain.edu.ag. Does the function support foreign domains?
The domain is hosted on Google Apps so mail should be received in the same way. No messages are in SPAM which lead me to explore further. So I created a test script to send mail, and noticed that mail doesn't seem to be sending.
This is what I used for testing purposes:
<?php
$to = "mymail#domain.edu.ag,mymail#gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
The result was that the #gmail message was received but not the #edu.ag email address. What's going on here? There are not errors or anything and mail is received just fine from other senders.

Try doing this instead:
$to = array("mymail#domain.edu.ag", "mymail#gmail.com");
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
foreach($to as $to_addr) {
mail($to_addr, $subject, $body)
}
So you are looping through the email addresses in the array, and sending the mail statement for each one. I've had some trouble in the past using a regular string with commas.

Related

Why the first code works on the server, but the second one doesnt

The first code without $_Post works, the second one with $_POST doesnt. It is on the server in cpanel. Anything helps :)
I tried various things like changing the code in HTML, placing slashes, also using $_request over $_post.
This works -
$to_email = "example#example.hr";
$subject = "Simple Email Test via PHP";
$body = "Hi,nn This is test email send by PHP Script";
$headers = "From: me#example.hr";
if ( mail($to_email, $subject, $body, $headers)){
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
$to_email = "example#example.hr";
$subject = "Simple Email Test via PHP";
$body = "Poruka:$_POST[poruka]";
$headers = "From: $_POST[email]\n";
if ( mail($to_email, $subject, $body, $headers)){
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
</code></pre>
The first code sends the email, while the second one goes into echo ("Email sending failed...")

Failed to connect to mailserver at "localhost" port 25, verify your "SMTP"

I have tried every single way on the internet but non of those solve my problem. I'm using WAMP 2.2
I'm using a form to require nyu student email and when the student submit the form it will send to another nyu.edu email and receive a confirmation.
original code:
// send the notification email
$mailto = $EMAIL;//requied from the form
$subject = "Thank you for your nomination!";
$body =
"Dear ".$NAME.",
This confirms that we have received your nomination of ".$NOMINEE." for a teaching award. Thank you for your submission.
NYU Teaching Awards Team";
$headers = "From: somemail#example.com\n\n";
if (mail($mailto, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
//end notification email
// send the notification email
$mail_to = "somemail#example.com";
$email_subject = "New Teaching Award Nomination";
$email_body =
"A new teaching award nomination has been submitted by ".$NAME." nominating ".$NOMINEE.".";
$email_headers = "From: somemail#example.com\n\n";
if (mail($mail_to, $email_subject, $email_body, $email_headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
//end notification email
the error msg is Failed to connect to mailserver at "localhost" port 25, verify your "SMTP"
so then I tied to put
ini_set("SMTP","nyu.smtp.edu");
ini_set("smtp_port","587");
but it shows: Failed to connect to mailserver at "nyu.smtp.edu" port 587, verify your "SMTP"
I don't know what to do!! please help
"nyu.smtp.edu" doesn't look right. Try "smtp.nyu.edu". You might go back to using port 25.
Be sure that sendmail is installed on your server.
But you have to consider PEAR if you want more options in sending mails.

PHP Sending Email Error

I'm trying to send an email using PHP code, I'm sure the code is right but I'm not receiving any emails. Can anyone see a problem with this code:
<?php
$to = 'i7906890#bournemouth.ac.uk';
$subject = 'Registration Complete';
$message = 'Thank you for joining us at Arsenic & Vice';
$header = 'From: admin#arsenicandvice.co.uk';
if (mail($to, $subject, $message, $header)){
echo('<p>Sent</p>');
} else {
echo('<p>Fail</p>');
}
?>
I've tested your code on my server and it works fine, I've received the e-mail.
I've also run it so you can receive it on i7906890#...
The problem is on your hosting. Either your e-mail server (qmail...) has a long queue or it is stuck. Contact your server admin.

PHP Mail() fails with "User <user#example.com>", fine with "<user#example.com>"

Problem began with Magento not sending mails, and while debugging I came to this:
when using PHP mail function, it fails if $to contains Name.
<?php
$to = '<myname#gmail.com>'; //Works fine
$to = 'myname#gmail.com'; //Works fine
$to = 'Myname <myname#gmail.com>'; // This doesn't work! No mail and getting "delivery failed";
$subject = "Test";
$body = "How are you?";
if (mail($to, $subject, $body)) {
echo("Message successfully sent!");
} else {
echo("Message delivery failed...");
}
?>
This is a hosted account, so I don't have access to sendmail or any other configs.
Haven't found solutions to this specific problem, but found Magento plugin, which uses SMTP/Google Mail/Apps . Working fine, sending mails.
http://www.magentocommerce.com/magento-connect/aschroder-com-smtp-pro-email-free-and-easy-magento-emailing-for-smtp-gmail-or-google-apps-email.html

PHP Send Mail duplicating body

I have this script which sends an email for users to activate their accounts on my website, its working fine my only problem is that its sending the body of the message twice, Can anybody see and explain why?
$toemail = $_POST['produgg_email'];
// Send activation email
$to = $toemail;
$subject = "Website Activation";
$headers = "From: support#website\r\n" .
$body = "To activate your website.co.uk please click <a href='http://www.website.co.uk/activateuser.php?email=$toemail'>here</a>";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
You have pasted the code? If so, you have a dot instead of a ; at line 5...

Categories