Diego Barreiro Diego Barreiro - 21 days ago 6
PHP Question

How to post literally this icon: &


I'm trying to post a long text to another server for sending an email, but when the server sends the email, I'm not geting what I hope to get:

How it should be:
<a target='_blank' href='http://sosgram.ga/account/access/verify.php?id='NDA='&code=237804940a1a14644fbd1cdddc165d28> Clique aquí para activar la cuenta :)</a>

How it is:
<a target='_blank' href='http://sosgram.ga/account/access/verify.php?id='NDA='
- And after that, all message dissapears

The files that are connected:

SignUp File:

$id = $user_index->lasdID();
$key = base64_encode($id);
$id = $key;
$code = file_get_contents("PRIVATE");
$link = "http://sosgram.ga/account/access/verify.php?id='$id'&code=$code";

$message = "
<b>Hola $fullname,
Bienvenido a SOSgram</b><br><br>
Para completar su registro, simplemente clique en el siguiente link de verificación<br><br>
<a target='_blank' href='$link'>Clique aquí para activar la cuenta :)</a>
<i>Muchas gracias,<br>

$subject = "Confirmar Registro en SOSgram";


$msg = "<div class='alert alert-success fade in'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
<strong>Enhorabuena!</strong> Su registro se ha completado correctamente.<br>
En breve recibirá un email con un link de confirmación de su cuenta

I posted only the code that causes my error because I checked the other code and it works good

Functions File:

function send_mail($email,$message,$subject)
$url = 'PRIVATE/email.php';
$myvars = 'email=' . $email . '&message=' . $message . '&subject=' . $subject;

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );

Server Email File:

if ($_POST['email'] and $_POST['subject'] and $_POST['message']) {
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;

$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.sparkpostmail.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "SMTP_Injection";
$mail->Password = "PRIATE";
$mail->setFrom('verify@email.sosgram.ga', 'Verificación de Cuentas | SOSgram');
$mail->addReplyTo('support@email.sosgram.ga', 'Soporte | SOSgram');
$mail->Subject = "$subject";

if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
} else {echo "Bad Request";}

I supose that the error is in the postmethod, when the server sends the message, it interprets the link
as two separates post methods, because it has an & icon, so it trims the text and only sends the message until the &

How can I force the $_POST method to send the icon & as an icon and not as a separator in the method?



Use the urlencode function.

This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.


Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type.

Alternatively, use http_build_query:

Generate URL-encoded query string

$base_url = "http://sosgram.ga/account/access/verify.php?";
$query = http_build_query(Array(
    id => "'$id'", # Are you sure you want to surround the id with apostrophes?
    code => $code
$link = $base_url . $query;