exim4 vs gmail FROM field - smtp

I've configured exim on my server as MTA to work with gmail.
Here is a configuration:
gmail_login:
driver = plaintext
public_name = LOGIN
client_send = : myaccount1#gmail.com : mypassword
The configuration is OK and I'm able to send a mail using a php script:
$to = 'myaccount3#gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: myaccount2#gmail.com' . "\r\n" .
'Reply-To: myaccount2#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers)) {
echo 'mail() Success!' . "<br />\n";
}
else {
echo 'mail() Failure!' . "<br />\n";
}
However I've encountered an issue:
gmail shows myaccount1#gmail.com in the FROM field instead of the actual email specified in the FROM field in my script (myaccount2#gmail.com).
The reply-to field is OK.
Please, help to solve the issue.

Gmail overwrites any FROM value you specify. Gmail overwrites it with the authenticated FROM value.

Related

How do I format email headers

How do I format the information so when it's displayed in the Email client, it'll show line breaks and other html tags that' i've set in the .php file?
//proceed with PHP email.
$headers = 'From: '.$user_Email.'' . "\r\n" .
'Reply-To: '.$user_Email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$sentMail = #mail($to_Email, $subject, $user_Message .' -'.$user_Name, $headers);
would it be something like:
$message = '<b>$user_Message';

Password protect a page, and send notification email when logged in

Is there a way to password protect a page with an array of passwords (which in this case is email addresses), and then once someone successfully logs in a notification is sent to a specified email address letting us know that someone has logged in with the given password (email address).
Thanks.
You have to do this with a server-side language like PHP. You can't do this with pure HTML and Javascript, unless you plan to store the usernames and passwords in a plaintext array in your Javascript (Don't do this, it is madness!).
If you use PHP, you can send the username and password data via POST, and have the user accounts stored in a MySQL Database. You can then lookup the username and password and see if they match, and if they do, then you could use something like PHP's mail() function to email the user.
As already mentioned, you'll need to use PHP, and your question unfortunately isn't something that can be answered in a couple of lines.
Below won't fully give you your answers, but it may lead you in the right direction to achieving them:
For a tutorial on user login using PHP $_POST , you could try here. Instead of reading the username and passwords from a mysql database, it would be simple enough to read in from an array defined in your PHP file.
For mail, below is a php function to email users their password once it's been reset. You should be able to get the idea of how the mail() function works from it and what variables to populate so you can change it for your own needs. You would call the email function once you've determined that a user has logged in succesfully.
public static function EmailPassword($user_email, $user, $password)
{
$mailfrom = "user#website.com.au";
$eol = "\n";
$content = $eol;
$content .= "Password for " . $user . " is " . $password . $eol;
$subject = "Pasword reset for " . $user . " at website.com.au";
$boundary = md5(uniqid(time()));
$header = 'From: '.$mailfrom.$eol;
$header .= 'Reply-To: '.$mailfrom.$eol;
$header .= 'MIME-Version: 1.0'.$eol;
$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
$header .= 'X-Mailer: PHP v'.phpversion().$eol;
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($content).$eol;
//send the email
mail($user_email, $subject, $body, $header);
}

PHP mail MMS attaching image not working

Hello guys I am working on webapplication for sending multimedia messages upon user input of their phone numbers. I am successfully able to send emails with images in HTML form. Now, I am trying to send my customers MMS via PHP mail function, but the only thing they receive is the link that I send them with the message.
Here is what I have come up with so far.
<?php
$email = '1234567890#somenetwork.domain';
$link = $_COOKIE["coupon"];
$to = $email;
$subject = 'Some Subject';
$message = " Hello, This is Testing Text 8.0
<a href=\"https://encrypted-tbn0.gstatic.com/images? \
q=tbn:ANd9GcS0dA2aipmy9hwAitgD8U5n8l_afNBvxYc3gnOFi7hOGoGAGIHssw\">Your Link</a> ";
$message->addAttachment("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS0dA2aipmy9hwAitgD8U5n8l_afNBvxYc3gnOFi7hOGoGAGIHssw", "image/gif");
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: someone <support#someone.com>' . "\r\n";
mail($email, $subject, $message, $headers);
?>
When sending to a phone as MMS, you have to send the image as an attachment.
I found the following answer to be very helpful for easily sending attachments, even though it references "mail", not MMS:
Send attachments with PHP Mail()?
One of the issues is that you can't fetch that image in that fashion.
I.e. https://encrypted-tbn0.gstatic.com/images?\
q=tbn:ANd9GcS0dA2aipmy9hwAitgD8U5n8l_afNBvxYc3gnOFi7hOGoGAGIHssw
returns an empty file.
Also, since when can you send MMS via PHP's mail() function?
The most reliable way in my experience to send images via SMS/MMS is to send a WAP push msg.

How can I add smtp support?

First of all, I'm new here and PHP :).
My question is about Smtp support. My code is doing send recover password. But my hosting need smtp support. I didn't add it. I read a lot post but my knowledge basic.
How can I add smtp support?
function sendRecover($to, $title, $url, $from, $username, $salt) {
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$title.' <'.$from.'>' . "\r\n";
$subject = 'Password Recovery - '.$title;
$message = 'A password recover was requested, if you didn\'t make this action please ignore this email. <br /><br />Your Username: <strong>'.$username.'</strong><br />Your Reset Key: <strong>'.$salt.'</strong><br /><br />You can reset your password by accessing the following link: '.$url.'/index.php?a=recover&r=1';
return #mail($to, $subject, $message, $headers);
}
Use PHPMailer
The current "official" version of PHPMailer is available through Github:
https://github.com/Synchro/PHPMailer
For implementation you can refer the links below :
http://www.htmlgoodies.com/beyond/php/article.php/3855686/PHP-Mailer-Script-Step-by-Step.htm
or
http://phpmailer.worxware.com/index.php?pg=examplebsmtp
If you have access to edit the php.ini then you can do something like this:
[mail function]
SMTP = ssl://smtp.gmail.com
smtp_port = 465
username = info#Mmydomainname.com
password = myemailpassword
sendmail_from = info#mydomainname.com

newline in text area in html form doesn't remain once posted

I'm having a textarea in my contact form with php mail function. In php mail i have set the header to html.
But even if the user types like this
Line1....
Line2....
I'm getting in mail like this.
Line1....Line2....
What could be the reason?
Update:
The text area is as simple as this.
<textarea id ="msg" name="message" cols="" rows="5" class="msg">Message</textarea>
Its posted to this script with jquery ajax function
<?php
$sub = "Message Posted";
$email = "some#somewhere.com";
$message = "<b>Message :</b><br/>" . $_REQUEST["msg"];
$message = wordwrap($message, 70);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ifthi#ifthi.com' . "\r\n" .
'Reply-To: '. $_REQUEST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// Send
mail($email, $sub, $message,$headers);
?>
But when getting in email all are in a single line. Even if you write in 2 line and submit.
if you set your mail to HTML you should replace all line breaks with HTML Tags.
I think the PHP function you need is:
string nl2br ( string $string [, bool $is_xhtml = true ] )
<?php
//whatever you want to replace new lines with
$newLineCode = "<br/>";
$message = $_POST['myTextArea'] ; //unadulterad text we got via Post
$modifiedTextAreaText = ereg_replace( "\n", $newLineCode, $message);
echo " Result of Code Snippet " . $modifiedTextAreaText ;
?>