How to change the sender name of email on Ubuntu - email

I just installed ssmtp to send email with LAMP on Ubuntu.
And a simple script like this:
<?php
$additional_headers = 'From: someone#testing.com' . "\r\n";
$res = mail('myemail#gmail.com','test','test body', $additional_headers);
var_dump($res);
?>
I received the email but the sender name will put as "nobody" , so it is using the user name "nobody"? How can I change it? I'm new in Ubuntu...
Thanks.

Try changing your "Extra Headers" to also include a 'Reply-to' header EG:
$additional_headers = 'From: someone#testing.com' . "\r\n" .
'Reply-To: someone#testing.com' . "\r\n";
The way you have it SHOULD work, according to the documentation, but distance can vary depending on which MTA (Mail Transport Agent) your using.
The doc page is here : http://php.net/manual/en/function.mail.php
Additional:
Be aware, that in a lot of mail systems, you need to provide a valid DNS address too. On my mail server running ubuntu, if I give the from header as a domain that cannot be looked up using a valid DNS, the recipient address will appear blank.

Related

Why are the emails going to spam? [duplicate]

This question already has answers here:
Why is my e-mail still being picked up as spam? Using mail() function
(5 answers)
Closed 9 years ago.
I am sending an email using PHP but all the emails are going to the spam folder. Please tell me where I am making a mistake.
<?
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];
$ToEmail = "me#example.com";
$ToSubject = "Message from your site";
$EmailBody = "Name: $name\n
Email: $email\n
Phone: $phone\n
Message: $message\n";
$Message = $EmailBody;
$headers .= "Content-type: text; charset=iso-8859-1\r\n";
$headers .= "From:".$name." / ".$email."\r\n";
mail($ToEmail,$ToSubject,$Message, $headers);
header("location: thankyou.php");
?>
Long story short, if the recipient's server put your mail into the spam box, your program is working all right and there is nothing you can do.
Longer Story: Nowadays most mailing servers will check that the email is from a server that actually holds the domain corresponding to the email. Suppose you are sending with account abc#gmail.com, the server of the recipient's email checks if the server from which this mail comes is gmail.com. This is done by checking the SPF record .

MCRYPT DECRYPT email form w/encrypted email address

I pray someone can help me. I've been around and around...
The situation is this. I have visible encrypted email addresses that an individual takes and puts into a form (enctype="multipart/form-data)and completes the email form prior to mailing. My php on a different page attempts to decrypt the TO: field of the html email form.
This is my php code, testing to see if I indeed am decrypting:
if (isset($_POST['submit'])) {
//just to echo the encrypted input for the email to field ECHOES PERFECTLY
$to = $_POST['to'];
echo $to;
//above echo displays correctly below is a jumbled mess
echo "<br>";
$ivs = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_OFB);
$iv = mcrypt_create_iv($ivs, MCRYPT_RAND);
$key = "12yeshua34";
$message = $to;
$enc = mcrypt_decrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_OFB, $iv);
echo $enc;
}
This is what gets echoed:
feeb936a8e9896a849c67f011524f6f2e4d8
$p�������t���b�� �'����T���A�f~
As you can already tell I am also a newbie. And I believe I've read everything I could find... and I still can't solve this. If I could get this to decrypt, then I could remove the test portion of this code and get an email 'successfully sent off.
Thank you and FATHER BLESS jim
assuming your encryption process works fine and uses 3DES in OFB mode to encrypt the address with the provided key "12yeshua34", you will also need the IV used for encryption for that specific address in order to be able to decrypt ... mcrypt_create_iv($ivs, MCRYPT_RAND) will create a random IV each time ... you need the very same IV for both operations: encryption and decryption

PHP Mail - UTF 8 Encoding problems with Chinese characters

I have a PHP Mail script that sends out emails and I need to send some out in Chinese. I have the following code:
$email_header = "From: $from\n";
$email_header .= "X-Priority: 1\n"; //1 UrgentMessage, 3 Normal
$email_header .= "Return-Path: <$return>\n";
$email_header .= "Content-type: text/html; charset=utf-8\n";
mail($row["email"], '=?UTF-8?B?'.base64_encode($subject).'?=', $email_body, $email_header);
The issue I have is with both the Subject of the Email and the body - it is sending as follows:
Subject: ???????????
Body: ???????????????
?????
??????????????????????????????????????????????????
?????
Clearly not Chinese!!! If anyone can point me in the right direction, that would be great.
Thanks in advance,
Homer.
Looks like a database connection issue rather than a mailer issue. Perhaps forgot to do a set names utf-8...?

Swiftmailer won't send mail, but mail() will

PHP's mail() function sends mail fine, but Swiftmailer's Swift_MailTransport doesn't work!
This works:
mail('user#example.com', 'test '.date('H:i:s'), '');
But this does not:
$transport = Swift_MailTransport::newInstance('');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('test '.date('H:i:s'))
->setFrom('user#example.com')
->setTo('user#example.com')
->setBody('Testing one two three');
$result = $mailer->send($message);
(The user#example.com is replaced by a valid email address in my test code.)
The mail logs for both events look very similar in both cases, and it appears that mail is being sent in the latter.
Could there be something about the message constructed by Swiftmailer that is causing it to be blocked by a spam filter?
(By the way, I have tried using the SMTP transport, with no luck; I figured that since mail() works correctly, it would be trivial to switch to Swiftmail's Mail transport...)
Which mail server are you using(like your web server or gmail,yahoo..)
this is for gmail SMTP,
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername($login_id)
->setPassword($password)
;
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('test '.date('H:i:s'))
->setFrom('user#example.com')
->setTo('user#example.com')
->setBody('Testing one two three');
$result = $mailer->send($message);
if mail() function works, then SwiftMailer should also work.
Hope it worked for you, and helped you.

cakephp Activation Email Sending slow

I have a simple email sender for user account activation. Depending on which email address I use, I get significantly different response times: University email - 1 minute, Gmail - 3-4 hours, Yahoo - 1 or 2 days -- which seems bizarre. Has anyone else seen this phenomenon?
EDIT:
There weren't many responses (even for a bounty), but I'll try to explain my problem more clearly.
This probably isn't greylsting -- If I so a simple:
php mail ($to, $subject, $body) // this delivers instantly.
My cakephp code:
function __sendActivationEmail($id) {
$User = $this->User->read ( null, $id );
$this->set ( 'suffix_url', $User ['User'] ['id'] . '/' . $this->User->getActivationHash () );
$this->set ( 'username', $User ['User'] ['username'] );
$this->Email->to = $User ['User'] ['email'];
$this->Email->subject = 'Test.com - ' . __ ( 'please confirm your email address', true );
$this->Email->from = 'noreply#test.com';
$this->Email->template = 'user_confirm';
$this->Email->sendAs = 'text';
$this->Email->delivery = 'mail';
$this->Email->send ();
}
Causes delays from 13 minutes (ok; we'll deal with it) to 5-6 hours (less okay, since this is an activation email). For some of my users, it works instantly, but for other users (of the same service provider, i.e., gmail, it sees these delays).
Any clues?
The code looks fine, but it of course doesn't tell anything about the mail server's configuration.
3-4 hours I would put down to Greylisting, but 1-2 days is definitely too much. Is this reproducible? How many addresses have you tried this with?
What do the full headers of the (received) mails look like? The "received from: .... "path should tell you at which point it took 1-2 days to deliver.
Maybe you can install PHPMailer as a Vendor and create a Component called "Mail"...
And don't forget to authenticate with your SMTP server! :)
Ignore the whole PHP element of it for a moment.
If its a linux server for example, send a mail from the command line e.g. mail myemail#me.com
see if the same thing is happening that way. Its quite likely its a server configuration issue not a php or cakePHP issue.
Look up a few basics like having a FQDN and maybe look into setting up SPF records for your email. Make sure the emails are coming from your domain name not someone elses e.g. not the users email.
Also check if you have email spam software set up that could be grey listing you email on the way out (unlikely but possible). the mostly like thing is the destination spam filter is delaying it. Try send to a gmail account and see if it gets through fine or goes into spam.
Do all this without touching PHP, if all is going fine there then set up a basic php script to do a basic email not using CakePHP, if that works fine then you know its CakePHP etc but I doubt it.
So after further digging, I realized that it was our server host's problem. We use Slicehost, and it just so happens that a range of ips that had been blacklisted included our own ip. We got our name off the list, and we're good to go.