All,
I have the following code:
$to = $friend_email[$x];
$subject = "Subject";
$message = "This is a message";
$from = $your_email;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
When the email sends (I'm using Godaddy's hosting service) it says From correctly but then in gmail it says via pxnlhgxxx.prod.xhx3.secureserver.net. Is there anyway to hide the via part or make it say something like website.com? Thanks for the help.
As per the mail() docs, you use the optional 5th parameter for the function and pass in the name of the server you'd like to masquerade as:
mail($to, $subject, $message, $headers, "-f sender#website.com");
If your hosting off godaddy then something like that will happen. You can use your own SMTP server, or use Google free SMTP Server (logging in with your gmail account). Host Gator does the same thing.
You can prevent Google from showing the 'via' notice by DKIM signing your outgoing mail to prove that you genuinely control the domain you're sending e-mail on behalf of.
Its all up to the configuration of the smtp server.
Related
I have this mail script on my page: mail('myadress#server.com', 'New client added by user', 'test message');
but I do not receive anything! (of course I added my real adress). I tried it with 2 different adresses, looked in my spam folder, etc... just nothing. but the script executes just fine.
Is there any log I can view or invoke to see exactly what happened?
thank you for your help!
<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
try this it will going to work for u ....
1) Check the return value from the mail() call:
$status = mail(...);
if (!$status) {
die("Mail failed");
}
If this fails, then PHP cannot even get the mail out the front door, and you'll have to figure out why - e.g. are you on a Windows box and haven't configured the mail options in php.ini?
2) Check your mail server's logs. Most Unix/Linux systems have a local mail server (the MTA) which will accept the mail from PHP. If it's misconfigured or having trouble, it may still accept the mail from PHP but then leave the mail to rot in a queue.
Perhaps your server's been placed on spam blackhole lists and it simply cannot deliver mail anywhere, which means you've probably got all of your test mails stuck in an outgoing queue that can't go anywhere.
Had to add the header "from" and use an email adress created on the server.
I am trying to send text messages to my phone from my server using php. I recently configured the server to send email, which it does (verified). It, however, goes into my spam box. When I try to send a message via sms I do not receive anything.
This is the script I am using:
$to = "myemailaddress#gmail.com";
$subject = "testing";
$body = "";
$headers = 'From: testemailaddress#gmail.com';
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
The address that I am using for sms is myphonenumber#txt.att.net in the 'To' field.
I am going to go out on a limb here and say this is a authentication issue, maybe.
Is there anything I need to configure further? (i.e. php.ini)
Most email providers/servers today rely heavily on spam filtering / dnsbl. Your webserver is not a know mail server, and you probably did not set up SPF or anything.
An approach to avoid all those issues would be to utilize a Google Mail address (or any other providers). And instead of the PHP mail function use something more complex like Swiftmailer, which generates Mail headers that are less commonly autoclassified as spam.
See also: Using php's swiftmailer with gmail
I'm trying to send mails from my server by google app.
I am using this php code :-
$to = "username#gmail.com";
$header = "From: username#netvigator.com";
$subject = "testing mail";
$message = "no reply pls";
ini_set("SMTP","smtp.gmail.com");
ini_set("SMTP_PORT", 23);
ini_set("sendmail_from","username#fullpiracy.com");
ini_set("auth_username","username#fullpiracy.com");
ini_set("auth_password","password");
mail($to, $subject, $message, $header);
Thanks in advance !
This was done with send mail open source library.
http://www.sendmail.com/sm/open_source/
I believe Gmail uses SSL (or TLS), so you should adjust your settings accordingly.
The port is usually 465 for ssl connection and 587 for TLS, and address are ssl://smtp.gmail.com and tls://smtp.gmail.com respectively.
Here is a link to a useful SO question that may be helpful.
I have a php mail script which works perfectly on a one host. However, when I attempt to use the same script on a network solutions host, the function returns true but no email ever sends.
//get mail function data
$case = $_POST['case'];
$to = addslashes(strip_tags($_POST['to']));
$message = addslashes(strip_tags($_POST['message']));
$subject = addslashes(strip_tags($_POST['subject']));
$message = addslashes(strip_tags($_POST['message']));
$from = "confirmation#website.co";
$headers = "From: $from\r\n";
//send email
if (mail($to,$subject,$message,$headers)){
//formatting for error message
$emailSent = "block";
$emailFailed = "none";
}
else //if the email fails to send
{
$emailSent = "none";
$emailFailed = "block";
}
?>
Does anyone know if different hosts require specific info in mail script?
This is a question for Network Solutions customer support. Sending mail from shared hosting servers is usually well locked down -- if they allow it at all, it's throttled. Also, calling mail just means the message was successfully passed to sendmail, not that the mail ever left the server. It could be sitting in a queue to be sent, it could have bounced for a million reasons beyond your control, etc.
Some hosts have this issue. On mine (Mosso), I had to adjust the last parameter (from) like so:
mail($to, $subject, $message, $headers, "-f".$from)
May not be the solution for NetSol but worth a try. I know some hosts disable the script and require using the smtp class to send mail.
This is assuming, of course, everything is correct with your DNS and MX records. If you're trying to send from an account that is different than the domain being sent from, some providers will automatically block that.
It maybe that they have not enabled php mail, but ask the host for specifics.
Looking at your code it is not cleaning the input sufficiently. take a look at the is_forbidden function here:
http://thedemosite.co.uk/phpformmailer/source_code_php_form_mailer_more_secure_than_cgi_form_mailers.php
I have 2 sites where mail is sent to two vanity gmail accounts. I'm using PHP to handle the mail, but the mail is not showing up at gmail (not in spam/junk, it just doesn't show up). If I switch the PHP to send to my personal hotmail account, the mail shows up. Same for a personal email account through my ISP.
The mail used to show up at those 2 vanity gmail accounts, any ideas why they would just stop?
There is a possibility you did not set proper header data, and those emails are blocked even before reaching spam folder.
Try adding something like this:
$headers = 'From: your#email.com' . "\r\n" .
'Reply-To: some#email.com';
This is the fourth parameter of mail() function.
I have encountered problems in the past where certain free email providers would not receive any email from my servers.
I found that a few things can be the culprit, on top of putting the correct headers in the actual message:
Make sure your server is configured for reverse dns lookup
Make sure you are not running an open smtp relay
Make sure your server did not wind up in any email blacklists (if you had an open relay, you probably got blacklisted.
Chances are, PHP is sending the email just fine, but the Google servers are rejecting any messages coming from your server.
You can test this by doing a quick:
mail -s Test you#gmail.com < /dev/null
If your server is okay, you will receive a message in your gmail, if you don't, PHP isn't the problem.
I've found having a proper SPF record for your domain really helps
http://www.openspf.org/SPF_Record_Syntax
Seems more likely that this is a server configuration issue and not a PHP issue.
As a side note I've found gmail more tolerant than our local system, so I've been able to get messages out to my gmail account, but not my account on the hosting domain.
I don't think Google uses third-party black lists, but they do care about server configuration (does it identify itself correctly, have matching SPF and RDNS records, respond to commands properly). You might try a couple of testing services like this or this.
I see it is too late but ... following code is working for gmail.
<html>
Mail Responder:<br><br>
<?php
$to = $_REQUEST['MyEmail'] ;
$subject = $_REQUEST['subject'] ;
$greeting = $_REQUEST['greeting'] ;
$realname = $_REQUEST['realname'] ;
$HisEmail = $_REQUEST['HisEmail'] ;
$message = $_REQUEST['message'] ;
$headers = 'From: '.$HisEmail;
//$headers = 'From: $HisEmail' . "\r\n" .
//'Reply-To: some#email.com';
$send = mail($to, $subject, $greeting."\n"."\n".$realname."\n"."\n".$HisEmail."\n"."\n".$message, $headers );
if ($send)
$mailReturns = "Mail sent successfully.";
else
$mailReturns = "Mail sent failed.";
?>
<?php echo $mailReturns; ?>
</html>