I am attaching my email code. I want to add an image in my body section with a message in this code.
require_once "../lib/Mail-1.4.1/Mail.php";
$from = 'someone#gmail.com';
$to = $mail;
$subject = 'Account Confirmation';
$body = 'Thanks for registering yourself, your login credentials are as
follows;'."\r\n".'Your User Name is: '.$uname.''."\r\n".'Your Password is:
'.$pass1.'';
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'someone#gmail.com',
'password' => '12345678'
));
$mail = $smtp -> send($to, $headers, $body);
if(PEAR::isError($mail)){
echo '<p>'.$mail->getMessage().'</p>';
}
else{
echo "<script>alert('Successfully Registered! Your credentials have been
sent on email that you have given in the form')</script>";
}
this is my email code, in body I want to add an image/logo.
Use for embedding image AddEmbeddedImage
you can also add an image as inline attachment with the content ID of my-photo, you would access it within the HTML body using <img src="cid:my-photo" alt="my-photo">.
In detail, here is the function to add an embedded attachment:
$mail->addEmbeddedImage($filename, $cid);
Related
I am working on a php website,Using google smtp to send mail,The code is working fine and it is sending mail to inbox, Through google smtp.But now have changed the $username and $password,It is showing me this error,Thankyou in advance
Error! authentication failure [SMTP: Invalid response code received
from server (code: 534, response: 5.7.14 Please log in via your web
browser and 5.7.14 then try again. 5.7.14 Learn more at 5.7.14
https://support.google.com/mail/answer/78754 y11-v6sm11496340pfn.92 - gsmtp)]
<?php
require_once 'Mail.php'; //this loads up PEAR Mail
if (!class_exists('Mail')) { die('Error: The PEAR Mail class does not exist.'); }
$host = 'ssl://smtp.gmail.com';
$username = '****#gmail.com'; //replace this with your new Gmail address
$password = '****'; //replace this with your new Gmail account password
$port = '465';
$from_email = $username;
$from = '"california worker company" <'.$from_email.'>'; //put your name in here, but keep the double quotes
$to = '"california worker company" <softphoton002#gmail.com>'; //put in your name and main email address to send a test to
$subject = 'California Worker Lead for GENERAL CONTRACTORS';
$myname = $_REQUEST['name'];
$myemail = $_REQUEST['email'];
$myphone = $_REQUEST['phone'];
$annualpayroll = $_REQUEST['annualpayroll'];
$numberofemployees = $_REQUEST['numberofemployees'];
$yourbusinesstype = $_REQUEST['yourbusinesstype'];
$healthinsurancecarrier = $_REQUEST['healthinsurancecarrier'];
$payrollservicemethod = $_REQUEST['payrollservicemethod'];
$body = 'Hello Admin <br/> You get a new lead for GENERAL CONTRACTORS.<br/>
Name:'.$myname.'<br/>
Email:'.$myemail.'<br/>
Phone:'.$myphone.'<br/>
Annual Payroll:'.$annualpayroll.'<br/>
Member of Employees:'.$numberofemployees.'<br/>
Business Type:'.$yourbusinesstype.'<br/>
Health Insurance Carrier:'.$healthinsurancecarrier.'<br/>
Payroll Service Method:'.$payrollservicemethod.'<br/>';
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject,
'Reply-To' => $from_email,
'MIME-Version' => 1,
'Content-type' => 'text/html;UTF-8'
);
$params = array(
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password
);
$smtp = Mail::factory('smtp', $params);
$mail = $smtp->send($to, $headers, $body);
// To user email
$headerss = array(
'From' => $from,
'To' => $myemail,
'Subject' => $subject,
'Reply-To' => $from_email,
'MIME-Version' => 1,
'Content-type' => 'text/html;UTF-8'
);
$paramss = array(
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password
);
$smtps = Mail::factory('smtp', $paramss);
$bodys = 'Hello '.$myname.'<br/>
We received your message for Quote on GENERAL CONTRACTOR. We will reply you in next 24-48 hours.<br/>
Thank you';
$mails = $smtps->send($myemail, $headerss, $bodys);
if (PEAR::isError($mail)) {
echo '<p>Error! '.$mail->getMessage().'</p>';
} else {
header("Location: http://californiaworkercomp.com/general-contractors?success=1");
//echo '<p>Your test message was sent successfully.</p>';
}
?>
I am trying to send mail to gmail account from my web site. It seems that everything is fine at the code level. Can you guys please look into this issue: even if i run this script, mail is not received to gmail Account.
<?php
if(isset($_POST['submit'])){
ini_set('SMTP','localhost');
$msg='Name : '.$_POST['name']."\n"
.'Email : '.$_POST['email']."\n"
.'Message : '.$_POST['message'];
mail("aa#gmail.com","Message from Contact Us",$msg);
}
else{
echo 'cannot send email';
}
?>
I think you will install phpmailer(http://pear.php.net/) and then send through smtp here is example code:
require_once "Mail.php";
$from = '<from#gmail.com>';
$to = '<to#yahoo.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'your gmail ',
'password' => 'your password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
I need my php script to email me some variables which is parsed to it.
I receive the email properly when any text is passed:
mypage.php?url=hello
But I do not receive the email if an url is passed:
mypage.php?url=http://www.google.com
I searched for hours but didn't found any way to do it.
This is the php script:
<?php
// Pear Mail Library
require_once "Mail.php";
$name = $_POST['name'];
$url = $_POST['url'];
$from = '<noreply#website.com>';
$to = '<me#gmail.com>';
$subject = 'Hi!';
$body = '
Name: '.$name.'
The url is: '.$url.'
';
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'mail#gmail.com',
'password' => 'password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<h1>Message successfully sent!</h1>');
}
?>
When an actual url is parsed, I don't recive the email but also no error is shown.
As #Xorifelse said, I used addslashes function and it worked. I got the email properly with the url in it.
Below is the working script:
<?php
// Pear Mail Library
require_once "Mail.php";
$name = $_POST['name'];
$url = $_POST['url'];
$from = '<noreply#website.com>';
$to = '<me#gmail.com>';
$subject = 'Hi!';
$body = '
Name: '.addslashes($name).'
The url is: '.addslashes($url).'
';
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'mail#gmail.com',
'password' => 'password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<h1>Message successfully sent!</h1>');
}
?>
I have a bit of a strange one. Using PHP Pear Mail I am sending an HTML email with a link in to a subdomain http://mysub.mydomain.co.uk
$body='<html><body><strong>Hello '.$forename.'</strong><br><br>Thank you for registering your details. To complete the process, please follow the link below in this email.<br><br>
Complete Verification Here</body></html>';
$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$mime = new Mail_mime();
$mime->setHTMLBody($body);
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password)
);
$mail = $smtp->send($to, $headers, $body);
The email gets sent fine and if I print the body of the email onto the screen from the page sending the email the link works fine. However when it arrives in an email in MS outlook it is taking the first 2 characters out of myvalue in the link. If myvalue=12345678 it says myvalue=345678 and displays the link incorrectly for example it shows the above as ttp://mysub.mydomain.co.uk/?V=345678. Notice it removes the H in the http address and also adds a forward slash before the ?v= and the first 2 digits 12 are also missing. It then fails to open the link as it is displaying it incorrectly as a http link. The email also does not arrive as an HTML email at Gmail and there is no link.
Any idea what I am missing here?
Eventually found the issue
In the body text I had to replace every occurrence in the body of
"
with ASCII code
'
Now working fine
You don't have to manipulate the body text outside of the mail_mime package, you need to mime encode the body with it:
$mime = new Mail_mime();
$mime->setHTMLBody($body);
$mimebody = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory(
'smtp',
[
'host' => $host,
'auth' => true,
'username' => $username,
'password' => $password,
'port' => $port
]
);
// send email
$mail = $smtp->send($to, $headers, $mimebody);
I'm using Pear PHP Mailer to send an email through SMTP to a number of recipients, but for each one, it sends an additional email to the sender's email address as well.
This is my code: Any help is appreciated.
...
$from = "$from_email_name <$from_email_addr>";
$html_body = "$html";
$crlf = "\r\n";
$hdrs = array(
'From' => $from,
'Subject' => $subject
);
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setTXTBody($text_body);
$mime->setHTMLBody($html_body);
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail = Mail::factory('mail',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail->send($to_email_addr, $hdrs, $body);
....
Also, on the email it is sending to my sender address, its saying the correct recipient name and sender information, but its like the sender is getting a copy of each one it sends out.
It could be a "service" of your mail server provider to automatically put mails sent via the SMTP server in your IMAP/POP mail box. Ask him if that's the case.