This has to be a simple and stupid question but cant seem to figure it out.
What I want to do is something like:
$message = include ('./myfile.php');
Obviously such does not work, but is there a way to accomplish this if that code worked.
Thanx
Here is full code (abbreviated):
require_once ('./connect.php');
$db = mysqli_connect($db_hostname,$db_username,$db_password,"paratb_members");
$result = mysqli_query($db,"SELECT * FROM board where accesskey = 'CHHXN5Jdwu'");
while ($row = mysqli_fetch_array($result)) {
extract($row);
$message = include './questions/resignation.php';
$subject = "IAP Ballot";
$headers = "From: xxxx" . "\r\n";
$headers .= "Reply-To: xxxx" . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$fromEmail = "xxxx";
$fifth = "-f" . $fromEmail;
$to = "$fname $lname <$email>";
mail($to, $subject, $message, $headers, $fifth);
echo "Email sent to $lname: $email<br>";
You can first read file & store data in variable which contain file's data then you can use that variable.
fopen("myfile.php", "r");
$lines = file("myfile.php");
$message = '';
foreach($lines as $value) {
$message .= $value." ";
}
echo ($message);
Related
I am using this basic php code to send out a html email.
When i use email#email.com as a to address the script works.
However, when i try to use email.2015#gmail.com the script says:
Parse error: syntax error, unexpected '#' in /home/u925912002/public_html/send_email.php on line 3
My code:
<?php
$to = ‘email.2015#gmail.com’;
$subject = 'I need to show html';
$from ='example#example.com';
$body = '<p style=color:red;>This text should be red</p>';
ini_set("sendmail_from", $from);
$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
$headers .= "Content-type: text/html\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}
?>
please can someone show me what i'm doing wrong. thanks
For your question recently closed: https://stackoverflow.com/questions/34106770/send-email-using-php-from-address-not-working
Try this:
$headers .= "From: Your Name <$from>\r\n";
and you can also add the 5th mail parameter:
mail($to, $subject, $body, $headers, '-finfo#userforum.com').
Works for me with these headers:
$from = "$name <$email>\r\n";
$to = "$username <$useremail>\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
you are using Apostrophe(‘) instead of quotes(')
try this -
$to = 'email.2015#gmail.com';
instead of this -
$to = ‘email.2015#gmail.com’;
I set up a simple php contact form. It is working so far, I get the emails, that is not the issue. The only thing that is not working, is the "From" and "Reply-To" field. The email I receive is from www-data#hostname.com and it also replies to that address. I don't know what I might have overlooked :(
<?php
$vorname = $_POST['vorname'];
$nachname = $_POST['nachname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$club = $_POST['club'];
$handicap = $_POST['handicap'];
$spieler = $_POST['spieler'];
$bemerkungen = $_POST['bemerkungen'];
$from = 'Von: Kontaktformular';
$to = 'edited for this question';
$subject = 'Anmeldung';
$body = "Von: $vorname $nachname\n E-Mail: $email\n Telefon: $phone\n Club: $club\n Handicap: $handicap\n Spieler: $spieler\n Bemerkung: $bemerkungen ";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if(!isset($_POST['submit'])) {
if (mail ($to, $subject, $body, $from)) {
header("Location: edited.html");
} else {
header("Location: edited.html");
}
}
?>
Thanks for any hint!
Looks like $headers is not being used in your mail function.
I am trying to send mail to all users that have no created reports in one month, also trying to send mail to this users with foreach loop and with mail function, when i refresh one by one then it sends mail one by one, then it works. i want to send mail to all this users in one time.
$from = "xxx#xxx.com";
$subject = "";
$headers = "";
$inc = 0;
foreach($query->result_array() as $row)
{
$inc++;
$to = $row['us_email'];
$to_date = $row['report_date'];
if($to_date != "0000-00-00")
{
$subject = "Hello! (Reports Are Not Created).";
//begin of HTML message
$message = "1 month above you should create reports.";
}
else if($to_date == "0000-00-00")
{
$subject = "Hello! (Generate Reports).";
//begin of HTML message
$message ="generate reports to get more.";
}
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "To: User <".$to.">, Admin <".$from.">" . "\r\n";
$headers .= "From: Complete Online Marketing <".$from.">" . "\r\n";
$headers .= "Reply-To: Recipient Name <".$from.">";
$headers .= "Cc: [email]".$from."[/email]" . "\r\n";
$headers .= "Bcc: [email]".$from."[/email]" . "\r\n";
// now lets send the email.
if(mail($to, $subject, $message, $headers))
{
echo $inc.") ".$row['us_firstname']." ".$row['us_lastname']." - Sending Success...\n";
$ins = array('report_mail'=>'0');
$this->db->update('se_user', $ins, array('us_id' => $row['us_id']));
}
else
{
echo $inc.") ".$row['us_firstname']." ".$row['us_lastname']." - Sending Fail...\n";
}
}
I have a list of subscribers who I am trying to send a HTML type email to (essentially a news letter). But currently, it is just sending plainly and I can't seem to figure how to make it look better.
I've searched through other questions but can't seem to apply the answers to my own code, so could someone help? Code is shown below:
<?php
$user = "example";
$password = "example";
$host = "example";
$dbase = "example";
$table = "example";
$from= 'example';//specify here the address that you want email to be sent from
$subject= $_POST['subject'];
$body= $_POST['body'];
// Connection to DBase
$dbc= mysqli_connect($host,$user,$password, $dbase)
or die("Unable to select database");
$query= "SELECT * FROM $table";
$result= mysqli_query ($dbc, $query)
or die ('Error querying database.');
while ($row = mysqli_fetch_array($result)) {
$firstname= $row['firstname'];
$lastname= $row['lastname'];
$email= $row['email'];
$msg= "Dear $firstname $lastname,\n$body";
mail($email, $subject, $msg, 'From:' . $from);
echo 'Email sent to: ' . $email. '<br>';
}
mysqli_close($dbc);
?>
So I have a message box where I can type a message but how would I make that message box, html style? So I can add in H2 etc tags? Or just make the email like a html newsletter
I have put example in on purpose
You need to send headers with html declared: example
$to = 'person#example.com';
$subject = 'Your subject';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: you#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = // your html code here
mail($to, $subject, $message, $headers);
For that you need to set your headers as text/html
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
and pass that to your mail() function.
Something like this..
mail($to, $subject, $msg, $headers);
Your Modified Code
$msg= "<h3>Dear $firstname $lastname</h3>,<br><br><b>$body</b>"; //<-- Added some basic formatting
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Yourname <'.$from.'>' . "\r\n";
mail($to, $subject, $msg, $headers);
Refer : PHP Manual
Use PHP Mailer Class instead of mail()
$mail = new PHPMailer();// defaults to using php "mail()"
$mail->SetFrom("frommail");
$mailAdmin->AddAddress("tomail");
$mailAdmin->Subject = $subject;
$mailAdmin->MsgHTML($message);
$mailAdmin->IsHTML(true);
$mailAdmin->Send();
You just need to include a class file phpmailer class file wich can be downloaded online.
I am using this script to send notificaitons to users friends. the problem is that all recepieints get to see who else got this email. How do i tweak the code so the emails still get sent to all but they can't see who else got it?
Code:
$sql = "SELECT STRAIGHT_JOIN DISTINCT email from
friend_email_ids WHERE my_id='$id'";
$result = mysql_query($sql);
$query = mysql_query($sql) or die ("Error: ".mysql_error());
if ($result == "")
{
echo "";
}
echo "";
$rows = mysql_num_rows($result);
$emails = array();
if($rows == 0)
{
print("");
}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
array_push($emails, $row['email']);
{
$email = $row['email'];
print("");
}
}
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: $usermail\r\n";
$subject = "$full_name added";
$message = "<html><body>";
$message .= "Hello, <br><br>$full_name posted someth<br><br>";
$message .= "<a href=www.domain.com/signup.php?t=&sign=>Click here.</a><br><br>";
$message .= "</body></html>";
mail(implode(",", $emails), "Subject: $subject",
$message, "$headers" );
echo "";
Just use BBC for all recipients:
Bcc: recipients get a copy of the email, but their email address is
automatically deleted at delivery. Nobody except you and the Bcc:
recipient will know that they got a copy, and their email address will
not be exposed.
-> http://email.about.com/od/emailmanagementtips/qt/How_to_Send_an_Email_to_Undisclosed_Recipients.htm
Use the additional_headers fields to add a BCC* address . See the manual
From the manual page:
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
the "birthdaycheck" email is hidden.
*(Blind Carbon Copy)
In you script it would become something like this:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: $usermail\r\n";
////////////pay attention here
$headers .= "BCC: ".implode(",", $emails)."\r\n";
$to = "youremail#domain.com"; //the mail in the "TO", visible to all. there has to be 1.
////////////////////////
$subject = "$full_name added";
$message = "<html><body>";
$message .= "Hello, <br><br>$full_name posted someth<br><br>";
$message .= "<a href=www.domain.com/signup.php?t=&sign=>Click here.</a><br><br>";
$message .= "</body></html>";
mail($to, "Subject: $subject",
$message, "$headers" );
echo "";
Put the actual sending of messages in the loop. That way you will send the e-mail to each recipient individually instead of all at once.
From PHP.net you'll find that the Bcc feature of mail() is what you need to use.
Like zoy (for multiple peeps):
$headers .= 'Bcc: someone#example.com,someone2#example.com,someone3#example.com,someone4#example.com,' . "\r\n";
Happy Haxin!
_wryteowl