Enziguri Posted June 14, 2012 Report Share Posted June 14, 2012 Boa Noite, estou a tentar por este script a funcional, quer dizer, ele funciona mas com bugs, não sei se o problema é do script ou do serviço de alojamento/dominio que estou a usar... dai estar a colocar esta questão aqui antes de contactar... Bem, 1º os caracteres "é, ã, â, etc etc" aparecem como pontos de interrogação no titulo do email na caixa de entrada do email pago, mas, se enviar o mesmo email para o gmail já mostra bem os acentos etc... pode ser problema deste script ou do email pago? 2º - quando envio o email o nome do remetente (eu) aparece igual ao user do painel de administração do alojamento... há maneira de mudar isso aqui no script? obrigado desde já. The below email script is for PHP emailing with SMTP authentication. <?php //new function $to = "you@your-domainname.com"; $nameto = "Who To"; $from = "script@your-domainname.com"; $namefrom = "Who From"; $subject = "Hello World Again!"; $message = "World, Hello!"; authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> <?php /* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */ //This will send an email using auth smtp and output a log array //logArray - connection, function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message) { //SMTP + SERVER DETAILS /* * * * CONFIGURATION START * * * */ $smtpServer = "mail.ukdns.biz"; $port = "25"; $timeout = "30"; $username = "your-email-address@domain.com"; $password = "Your-POP3-Password"; $localhost = "mail.ukdns.biz"; $newLine = "\r\n"; /* * * * CONFIGURATION END * * * * */ //Connect to the host on the specified port $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout); $smtpResponse = fgets($smtpConnect, 515); if(empty($smtpConnect)) { $output = "Failed to connect: $smtpResponse"; return $output; } else { $logArray['connection'] = "Connected: $smtpResponse"; } //Request Auth Login fputs($smtpConnect,"AUTH LOGIN" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authrequest'] = "$smtpResponse"; //Send username fputs($smtpConnect, base64_encode($username) . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authusername'] = "$smtpResponse"; //Send password fputs($smtpConnect, base64_encode($password) . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authpassword'] = "$smtpResponse"; //Say Hello to SMTP fputs($smtpConnect, "HELO $localhost" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['heloresponse'] = "$smtpResponse"; //Email From fputs($smtpConnect, "MAIL FROM: $from" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['mailfromresponse'] = "$smtpResponse"; //Email To fputs($smtpConnect, "RCPT TO: $to" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['mailtoresponse'] = "$smtpResponse"; //The Email fputs($smtpConnect, "DATA" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['data1response'] = "$smtpResponse"; //Construct Headers $headers = "MIME-Version: 1.0" . $newLine; $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine; $headers .= "To: $nameto <$to>" . $newLine; $headers .= "From: $namefrom <$from>" . $newLine; fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n"); $smtpResponse = fgets($smtpConnect, 515); $logArray['data2response'] = "$smtpResponse"; // Say Bye to SMTP fputs($smtpConnect,"QUIT" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['quitresponse'] = "$smtpResponse"; //insert var_dump here -- uncomment out the next line for debug info //var_dump($logArray); } ?> Link to comment Share on other sites More sharing options...
tiagotavares Posted June 15, 2012 Report Share Posted June 15, 2012 Boas, Em relação ao teu primeiro problema é de fácil resolução, fiz uma função mesmo a pouco tempo sobre isso, não está de maneira nenhuma optimizada, mas funciona (se não gostares da função e quiseres fazer a tua ou procurar noutro sitio visita-me): function htmlAccents($text) { //Grave $text = strtr($text, "À", "À"); $text = strtr($text, "È", "È"); $text = strtr($text, "Ì", "Ì"); $text = strtr($text, "Ò", "Ò"); $text = strtr($text, "Ù", "Ù"); $text = strtr($text, "à", "à"); $text = strtr($text, "è", "è"); $text = strtr($text, "ì", "ì"); $text = strtr($text, "ò", "ò"); $text = strtr($text, "ù", "ù"); //Acute $text = strtr($text, "Á", "Á"); $text = strtr($text, "É", "É"); $text = strtr($text, "Í", "Í"); $text = strtr($text, "Ó", "Ó"); $text = strtr($text, "Ú", "Ú"); $text = strtr($text, "Ý", "Ý"); $text = strtr($text, "á", "á"); $text = strtr($text, "é", "é"); $text = strtr($text, "í", "í"); $text = strtr($text, "ó", "ó"); $text = strtr($text, "ú", "ú"); $text = strtr($text, "ý", "ý"); //Circumflex $text = strtr($text, "Â", "Â"); $text = strtr($text, "Ê", "Ê"); $text = strtr($text, "Î", "Î"); $text = strtr($text, "Ô", "Ô"); $text = strtr($text, "Û", "Û"); $text = strtr($text, "â", "â"); $text = strtr($text, "ê", "ê"); $text = strtr($text, "î", "î"); $text = strtr($text, "ô", "ô"); $text = strtr($text, "û", "û"); //Tilde $text = strtr($text, "Ã", "Ã"); $text = strtr($text, "Ñ", "Ñ"); $text = strtr($text, "Õ", "Õ"); $text = strtr($text, "ã", "ã"); $text = strtr($text, "ñ", "ñ"); $text = strtr($text, "õ", "õ"); //Umlaut $text = strtr($text, "Ä", "Ä"); $text = strtr($text, "Ë", "Ë"); $text = strtr($text, "Ï", "Ï"); $text = strtr($text, "Ö", "Ö"); $text = strtr($text, "Ü", "Ü"); $text = strtr($text, "Ÿ", ""); $text = strtr($text, "ä", "ä"); $text = strtr($text, "ë", "ë"); $text = strtr($text, "ï", "ï"); $text = strtr($text, "ö", "ö"); $text = strtr($text, "ü", "ü"); $text = strtr($text, "ÿ", "ÿ"); return $text; } Em relação ao teu 2º problema não há muito que possa fazer, nunca trabalhei com SMTP mas pode ser que isto ajude link Espero ter ajudado Tiago Tavares Link to comment Share on other sites More sharing options...
taviroquai Posted June 15, 2012 Report Share Posted June 15, 2012 Hmm... ok parece que estás a trabalhar em "baixo nível"... fsockopen... Para aquilo que precisas... enviar mails por smtp, penso que o melhor será usares uma biblioteca tipo PHPMailer (http://phpmailer.worxware.com/). Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 15, 2012 Report Share Posted June 15, 2012 Boas, Em relação ao teu primeiro problema é de fácil resolução, fiz uma função mesmo a pouco tempo sobre isso, não está de maneira nenhuma optimizada, mas funciona (se não gostares da função e quiseres fazer a tua ou procurar noutro sitio visita-me): function htmlAccents($text) { //Grave $text = strtr($text, "À", "À"); $text = strtr($text, "È", "È"); $text = strtr($text, "Ì", "Ì"); $text = strtr($text, "Ò", "Ò"); $text = strtr($text, "Ù", "Ù"); $text = strtr($text, "à", "à"); $text = strtr($text, "è", "è"); $text = strtr($text, "ì", "ì"); $text = strtr($text, "ò", "ò"); $text = strtr($text, "ù", "ù"); //Acute $text = strtr($text, "Á", "Á"); $text = strtr($text, "É", "É"); $text = strtr($text, "Í", "Í"); $text = strtr($text, "Ó", "Ó"); $text = strtr($text, "Ú", "Ú"); $text = strtr($text, "Ý", "Ý"); $text = strtr($text, "á", "á"); $text = strtr($text, "é", "é"); $text = strtr($text, "í", "í"); $text = strtr($text, "ó", "ó"); $text = strtr($text, "ú", "ú"); $text = strtr($text, "ý", "ý"); //Circumflex $text = strtr($text, "Â", "Â"); $text = strtr($text, "Ê", "Ê"); $text = strtr($text, "Î", "Î"); $text = strtr($text, "Ô", "Ô"); $text = strtr($text, "Û", "Û"); $text = strtr($text, "â", "â"); $text = strtr($text, "ê", "ê"); $text = strtr($text, "î", "î"); $text = strtr($text, "ô", "ô"); $text = strtr($text, "û", "û"); //Tilde $text = strtr($text, "Ã", "Ã"); $text = strtr($text, "Ñ", "Ñ"); $text = strtr($text, "Õ", "Õ"); $text = strtr($text, "ã", "ã"); $text = strtr($text, "ñ", "ñ"); $text = strtr($text, "õ", "õ"); //Umlaut $text = strtr($text, "Ä", "Ä"); $text = strtr($text, "Ë", "Ë"); $text = strtr($text, "Ï", "Ï"); $text = strtr($text, "Ö", "Ö"); $text = strtr($text, "Ü", "Ü"); $text = strtr($text, "Ÿ", ""); $text = strtr($text, "ä", "ä"); $text = strtr($text, "ë", "ë"); $text = strtr($text, "ï", "ï"); $text = strtr($text, "ö", "ö"); $text = strtr($text, "ü", "ü"); $text = strtr($text, "ÿ", "ÿ"); return $text; } Em relação ao teu 2º problema não há muito que possa fazer, nunca trabalhei com SMTP mas pode ser que isto ajude link Espero ter ajudado se bem me lembro esta função é mais simples : function unicode($string) { $result = ""; for ($iter=0; $iter < mb_strlen($string); $iter++) { $char = mb_substr($string, $iter, 1); if (ord($char) > 127) { $result.= "\u"; $result.= str_pad(dechex(ord($char) >> 8), 2, "0", STR_PAD_LEFT); $result.= str_pad(dechex(ord($char) % 255), 2, "0", STR_PAD_LEFT); } else $result.= $char; } return $result; } IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Enziguri Posted June 15, 2012 Author Report Share Posted June 15, 2012 bem muito obrigado pelas ajudas, ajudaram-me imenso apesar de no final ter acabado por não usar estes codigos mas sim o tal que o CRLF mandou https://www.portugal-a-programar.pt/topic/29149-phpphp-mailer-tutorial/ Obrigado pela ajuda Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now