Send a fancy mail with PHPMailer from Beefree - php

I want to send an email with PHPMailer. The mail is a HTML made up mail with Beefree. First the whole email was a PHP variable, but then I get the email with the first part repeated. I think this is a result of having a head in the body, but I'm not sure.
To clear this out the mail I want to send is this (with fancy lay-out):
[image]
Hello John,
How are you?
Best regards!
But it is send like this:
[image]
Hello $name,
[image]
Hello $name,
<div style="Margin: 0 auto;min-width: 320px;max-width: 600px;ov
Now I saved my mail as beefree.php. It is possible to send it like this:
$mail->msgHTML(file_get_contents('beefree.php'));
The file is now send with a correct lay-out, but with variables, like 'Hello $name'.
To solve this I can do this:
ob_start();
include 'beefree.php'; //execute the file as php
$body = ob_get_clean();
and send it like this:
$mail->msgHTML($body);
Then the variables are inserted, I see the real name, but the email is like the second mail-example, except the real name is visible. The problem is why it has repeated parts and not the whole email. How can I send the mail like in the file_get_contents, but with the correct variables?

Related

How to echo user input within mail body

I'm working on php mailer and I've tried all possible means to echo out the user input within the mail body, but i keep getting an error. below is my code
$mail->isHTML(true);
$body="<p><center><img src='https://example.com/images/mail-icon.png'><br>Example</center></p>
<center><h3>You are welcome</h3></center><br>
<p>
$mail->='$_POST['fname']'
Answer for your question is very simple. So, I dont know how your form looks, but all you need to do is:
$body=$fname;
Perhaps, inside $body you can write also html message, as $body="<p>Dear,<br> You just received a message from:". $fname ."</p>";

Change hyperlink when sending group mails

When sending a group mail about assigning to a newsletter, I need to create a hyperlink button which redirects to: example.com/action.php?id=11 ... email=<%email>
I need to change the <%email> area depending on the recipient's email...
I've done some research, but haven't come up with any solution.
Thanks for any response.
assign variable in code eg
$email = "someone#somewhere.com";
include the variable with the string eg.
echo "example.com/action.php?id=11&email=$email";
You can keep something like <%email> as placeholder text in mail body of each mail text in group mail and later you can replace this with your original email by using str_replace() function when you actually sending mail in your loop before sending mail.
provide complete code you are trying to do so we can help you more with it.

PHP - Send an array with <pre> tags via email

I've created my first multi-page form using php.
I like the way that the form data can be output using -
echo '<pre>'.print_r($_POST,true).'</pre>';
However, instead of printing, I'd like to keep that formatting but have it sent via email using the mail function.
are you sending it as a html email? because it wont work in plain text
See example 4 http://php.net/manual/en/function.mail.php

HTML in php mail function

I have a contact form on my website so users can send me an email but I have run into a problem.
I want to use an HTML link inside the email and I also want the content the user is sending to me to be formated how they would like it.... let me explain.
If a user sends this:
Hello World!
Isnt it a great Day?
without using headers to enable html, then it says formated like that when it reaches me.
If I use headers (MIME) to enable html, to also include a link in the email (which I would like to do), then it reaches me as:
Hello World!Isnt it a great Day?
How can I include html, and also keep the email formatted properly?
Thanks
And hopefully all this makes sense :S
Use nl2br on your message - http://php.net/manual/en/function.nl2br.php
It will replace all newlines with HTML <br>
$message = nl2br($message, false);
The second parameter *is_xhtml* is optional if you want to send an HTML email instead of XHTML

Use PHPmailer or regualer PHP mail to send text: From $Phone-Number

Can I send a text message using PHP or PHPmailer and in the return use a phone number and not an email?
PHP mail() and PHPmailer makes me use a valid email with an "#" symbol. Is there a way around this?
You can put whatever you want in the from field, but don't expect your mail server, or the receiving mail server to accept it.
Better to set your from: field to something like this instead:
"123-123-1234 <noreply#yourdomain.com>"
That way, you can have a valid from address, and still display a number to the end user.

Categories